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

Breadcrumb

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

class ShortListSniff

Hierarchy

  • class \SlevomatCodingStandard\Sniffs\PHP\ShortListSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of ShortListSniff

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/ShortListSniff.php, line 12

Namespace

SlevomatCodingStandard\Sniffs\PHP
View source
class ShortListSniff implements Sniff {
    public const CODE_LONG_LIST_USED = 'LongListUsed';
    
    /**
     * @return array<int, (int|string)>
     */
    public function register() : array {
        return [
            T_LIST,
        ];
    }
    
    /**
     * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
     * @param int $pointer
     */
    public function process(File $phpcsFile, $pointer) : void {
        $fix = $phpcsFile->addFixableError('list(...) is forbidden, use [...] instead.', $pointer, self::CODE_LONG_LIST_USED);
        if (!$fix) {
            return;
        }
        $tokens = $phpcsFile->getTokens();
        
        /** @var int $startPointer */
        $startPointer = TokenHelper::findNext($phpcsFile, [
            T_OPEN_PARENTHESIS,
        ], $pointer + 1);
        $endPointer = $tokens[$startPointer]['parenthesis_closer'];
        $phpcsFile->fixer
            ->beginChangeset();
        FixerHelper::removeBetweenIncluding($phpcsFile, $pointer, $startPointer - 1);
        $phpcsFile->fixer
            ->replaceToken($startPointer, '[');
        $phpcsFile->fixer
            ->replaceToken($endPointer, ']');
        $phpcsFile->fixer
            ->endChangeset();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ShortListSniff::CODE_LONG_LIST_USED public constant
ShortListSniff::process public function * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
*
Overrides Sniff::process
ShortListSniff::register public function * Overrides Sniff::register
RSS feed
Powered by Drupal