You are here

public function DuplicateEntrySniff::process in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php \Drupal\Sniffs\InfoFiles\DuplicateEntrySniff::process()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/InfoFiles/DuplicateEntrySniff.php \Drupal\Sniffs\InfoFiles\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

File

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', array(
        $duplicate,
      ));
    }
  }
  return $phpcsFile->numTokens + 1;
}