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

Breadcrumb

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

function DisallowLongArraySyntaxSniff::process

Same name in this branch
  1. 11.1.x vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php \Drupal\Sniffs\Arrays\DisallowLongArraySyntaxSniff::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

2 calls to DisallowLongArraySyntaxSniff::process()
DisallowLongArraySyntaxSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php
Processes this test, when one of its tokens is encountered.
DisallowLongArraySyntaxSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php
Processes this test, when one of its tokens is encountered.
1 method overrides DisallowLongArraySyntaxSniff::process()
DisallowLongArraySyntaxSniff::process in vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php
Processes this test, when one of its tokens is encountered.

File

vendor/squizlabs/php_codesniffer/src/Standards/Generic/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php, line 40

Class

DisallowLongArraySyntaxSniff

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\Arrays

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $phpcsFile->recordMetric($stackPtr, 'Short array syntax used', 'no');
    $error = 'Short array syntax must be used to define arrays';
    if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
        // Live coding/parse error, just show the error, don't try and fix it.
        $phpcsFile->addError($error, $stackPtr, 'Found');
        return;
    }
    $fix = $phpcsFile->addFixableError($error, $stackPtr, 'Found');
    if ($fix === true) {
        $opener = $tokens[$stackPtr]['parenthesis_opener'];
        $closer = $tokens[$stackPtr]['parenthesis_closer'];
        $phpcsFile->fixer
            ->beginChangeset();
        $phpcsFile->fixer
            ->replaceToken($stackPtr, '');
        $phpcsFile->fixer
            ->replaceToken($opener, '[');
        $phpcsFile->fixer
            ->replaceToken($closer, ']');
        $phpcsFile->fixer
            ->endChangeset();
    }
}
RSS feed
Powered by Drupal