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

Breadcrumb

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

function DuplicateEntrySniff::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

int

Overrides Sniff::process

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php, line 47

Class

DuplicateEntrySniff
Make sure that entries in info files are specified only once.

Namespace

Drupal\Sniffs\InfoFiles

Code

public function process(File $phpcsFile, $stackPtr) {
    // Only run this sniff once per info file.
    $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4));
    if ($fileExtension !== 'info') {
        return $phpcsFile->numTokens + 1;
    }
    $contents = file_get_contents($phpcsFile->getFilename());
    $duplicates = $this->findDuplicateInfoFileEntries($contents);
    if (empty($duplicates) === false) {
        foreach ($duplicates as $duplicate) {
            $error = 'Duplicate entry for "%s" in info file';
            $phpcsFile->addError($error, $stackPtr, 'DuplicateEntry', [
                $duplicate,
            ]);
        }
    }
    return $phpcsFile->numTokens + 1;
}
RSS feed
Powered by Drupal