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

Breadcrumb

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

function SpaceInlineIfSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token in: the stack passed in $tokens.

Return value

void

Overrides Sniff::process

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Formatting/SpaceInlineIfSniff.php, line 47

Class

SpaceInlineIfSniff
Checks that there is no space between "?" and ":" inline if/else statements.

Namespace

Drupal\Sniffs\Formatting

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    // Handle the short ternary operator (?:) introduced in PHP 5.3.
    $previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true);
    if ($tokens[$previous]['code'] === T_INLINE_THEN) {
        if ($previous !== $stackPtr - 1) {
            $error = 'There must be no space between ? and :';
            $phpcsFile->addError($error, $stackPtr, 'SpaceInlineElse');
        }
    }
    
    //end if
}
RSS feed
Powered by Drupal