Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractLineCall.php

class AbstractLineCall

Hierarchy

  • class \SlevomatCodingStandard\Sniffs\Functions\AbstractLineCall implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of AbstractLineCall

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Functions/AbstractLineCall.php, line 21

Namespace

SlevomatCodingStandard\Sniffs\Functions
View source
abstract class AbstractLineCall implements Sniff {
    
    /**
     * @return array<int, (int|string)>
     */
    public function register() : array {
        return array_merge(TokenHelper::getOnlyNameTokenCodes(), [
            T_SELF,
            T_STATIC,
            T_PARENT,
        ]);
    }
    protected function isCall(File $phpcsFile, int $stringPointer) : bool {
        $tokens = $phpcsFile->getTokens();
        $nextPointer = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
        if ($tokens[$nextPointer]['code'] !== T_OPEN_PARENTHESIS) {
            return false;
        }
        $previousPointer = TokenHelper::findPreviousEffective($phpcsFile, $stringPointer - 1);
        return $tokens[$previousPointer]['code'] !== T_FUNCTION;
    }
    protected function getLineStart(File $phpcsFile, int $pointer) : string {
        $firstPointerOnLine = TokenHelper::findFirstTokenOnLine($phpcsFile, $pointer);
        return IndentationHelper::convertTabsToSpaces($phpcsFile, TokenHelper::getContent($phpcsFile, $firstPointerOnLine, $pointer));
    }
    protected function getCall(File $phpcsFile, int $parenthesisOpenerPointer, int $parenthesisCloserPointer) : string {
        $tokens = $phpcsFile->getTokens();
        $pointerBeforeParenthesisCloser = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisCloserPointer - 1);
        $endPointer = $tokens[$pointerBeforeParenthesisCloser]['code'] === T_COMMA ? $pointerBeforeParenthesisCloser : $parenthesisCloserPointer;
        $call = '';
        for ($i = $parenthesisOpenerPointer + 1; $i < $endPointer; $i++) {
            if ($tokens[$i]['code'] === T_COMMA) {
                $nextPointer = TokenHelper::findNextEffective($phpcsFile, $i + 1);
                if ($tokens[$nextPointer]['code'] === T_CLOSE_PARENTHESIS) {
                    $i = $nextPointer - 1;
                    continue;
                }
            }
            if ($tokens[$i]['code'] === T_WHITESPACE) {
                if ($tokens[$i]['content'] === $phpcsFile->eolChar) {
                    if ($tokens[$i - 1]['code'] === T_COMMA) {
                        $call .= ' ';
                    }
                    continue;
                }
                if ($tokens[$i]['column'] === 1) {
                    // Nothing
                    continue;
                }
            }
            $call .= $tokens[$i]['content'];
        }
        return trim($call);
    }
    protected function getLineEnd(File $phpcsFile, int $pointer) : string {
        $firstPointerOnNextLine = TokenHelper::findFirstTokenOnNextLine($phpcsFile, $pointer);
        return rtrim(TokenHelper::getContent($phpcsFile, $pointer, $firstPointerOnNextLine - 1));
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title Overrides
AbstractLineCall::getCall protected function
AbstractLineCall::getLineEnd protected function
AbstractLineCall::getLineStart protected function
AbstractLineCall::isCall protected function
AbstractLineCall::register public function * Overrides Sniff::register
Sniff::process public function Called when one of the token types that this sniff is listening for
is found.
453
RSS feed
Powered by Drupal