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

Breadcrumb

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

class EmptyLinesSniff

\Drupal\Sniffs\WhiteSpace\EmptyLinesSniff.

Checks that there are not more than 2 empty lines following each other.

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

Hierarchy

  • class \Drupal\Sniffs\WhiteSpace\EmptyLinesSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of EmptyLinesSniff

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/WhiteSpace/EmptyLinesSniff.php, line 24

Namespace

Drupal\Sniffs\WhiteSpace
View source
class EmptyLinesSniff implements Sniff {
    
    /**
     * A list of tokenizers this sniff supports.
     *
     * @var array<string>
     */
    public $supportedTokenizers = [
        'PHP',
        'JS',
        'CSS',
    ];
    
    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register() {
        return [
            T_WHITESPACE,
        ];
    }
    
    //end register()
    
    /**
     * 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();
        if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 1]) === true && $tokens[$stackPtr + 1]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 2]) === true && $tokens[$stackPtr + 2]['content'] === $phpcsFile->eolChar && isset($tokens[$stackPtr + 3]) === true && $tokens[$stackPtr + 3]['content'] === $phpcsFile->eolChar) {
            $error = 'More than 2 empty lines are not allowed';
            $phpcsFile->addError($error, $stackPtr + 3, 'EmptyLines');
        }
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
EmptyLinesSniff::$supportedTokenizers public property A list of tokenizers this sniff supports.
EmptyLinesSniff::process public function Processes this test, when one of its tokens is encountered. Overrides Sniff::process
EmptyLinesSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal