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

Breadcrumb

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

function DuplicatePropertySniff::process

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

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The current file being processed.:

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

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Classes/DuplicatePropertySniff.php, line 49

Class

DuplicatePropertySniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $properties = [];
    $wantedTokens = [
        T_PROPERTY,
        T_OBJECT,
    ];
    $next = $phpcsFile->findNext($wantedTokens, $stackPtr + 1, $tokens[$stackPtr]['bracket_closer']);
    while ($next !== false && $next < $tokens[$stackPtr]['bracket_closer']) {
        if ($tokens[$next]['code'] === T_OBJECT) {
            // Skip nested objects.
            $next = $tokens[$next]['bracket_closer'];
        }
        else {
            $propName = $tokens[$next]['content'];
            if (isset($properties[$propName]) === true) {
                $error = 'Duplicate property definition found for "%s"; previously defined on line %s';
                $data = [
                    $propName,
                    $tokens[$properties[$propName]]['line'],
                ];
                $phpcsFile->addError($error, $next, 'Found', $data);
            }
            $properties[$propName] = $next;
        }
        
        //end if
        $next = $phpcsFile->findNext($wantedTokens, $next + 1, $tokens[$stackPtr]['bracket_closer']);
    }
    
    //end while
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal