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

Breadcrumb

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

class InlineControlStructureSniff

Same name in this branch
  1. 11.1.x vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/ControlStructures/InlineControlStructureSniff.php \PHP_CodeSniffer\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff

\Drupal\Sniffs\ControlStructures\InlineControlStructureSniff.

Verifies that inline control statements are not present. This Sniff overrides the generic sniff because Drupal template files may use the alternative syntax for control structures. See http://www.php.net/manual/en/control-structures.alternative-syntax.php

@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer

Hierarchy

  • class \PHP_CodeSniffer\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff implements \PHP_CodeSniffer\Sniffs\Sniff
    • class \Drupal\Sniffs\ControlStructures\InlineControlStructureSniff extends \PHP_CodeSniffer\Standards\Generic\Sniffs\ControlStructures\InlineControlStructureSniff

Expanded class hierarchy of InlineControlStructureSniff

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/ControlStructures/InlineControlStructureSniff.php, line 27

Namespace

Drupal\Sniffs\ControlStructures
View source
class InlineControlStructureSniff extends GenericInlineControlStructureSniff {
    
    /**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
     * @param int                         $stackPtr  The position of the current token in
     *                                               the stack passed in $tokens.
     *
     * @return void
     */
    public function process(File $phpcsFile, $stackPtr) {
        $tokens = $phpcsFile->getTokens();
        // Check for the alternate syntax for control structures with colons (:).
        if (isset($tokens[$stackPtr]['parenthesis_closer']) === true) {
            $start = $tokens[$stackPtr]['parenthesis_closer'];
        }
        else {
            $start = $stackPtr;
        }
        $scopeOpener = $phpcsFile->findNext(T_WHITESPACE, $start + 1, null, true);
        if ($tokens[$scopeOpener]['code'] === T_COLON) {
            return;
        }
        parent::process($phpcsFile, $stackPtr);
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
InlineControlStructureSniff::$error public property If true, an error will be thrown; otherwise a warning.
InlineControlStructureSniff::$supportedTokenizers public property A list of tokenizers this sniff supports.
InlineControlStructureSniff::process public function Processes this test, when one of its tokens is encountered. Overrides InlineControlStructureSniff::process
InlineControlStructureSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal