You are here

public static function ClassFilesSniff::getPtr in Coder 8.2

Same name and namespace in other branches
  1. 8.3 coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php \Drupal\Sniffs\InfoFiles\ClassFilesSniff::getPtr()
  2. 8.3.x coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php \Drupal\Sniffs\InfoFiles\ClassFilesSniff::getPtr()

Helper function that returns the position of the key in the info file.

Parameters

string $key Key name to search for.:

string $value Corresponding value to search for.:

\PHP_CodeSniffer\Files\File $infoFile Info file to search in.:

Return value

int|false Returns the stack position if the file name is found, false otherwise.

2 calls to ClassFilesSniff::getPtr()
ClassFilesSniff::process in coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php
Processes this test, when one of its tokens is encountered.
RequiredSniff::process in coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php
Processes this test, when one of its tokens is encountered.

File

coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php, line 102

Class

ClassFilesSniff
Checks files[] entries in info files. Only files containing classes/interfaces should be listed.

Namespace

Drupal\Sniffs\InfoFiles

Code

public static function getPtr($key, $value, File $infoFile) {
  foreach ($infoFile
    ->getTokens() as $ptr => $tokenInfo) {
    if (preg_match('@^[\\s]*' . preg_quote($key) . '[\\s]*=[\\s]*["\']?' . preg_quote($value) . '["\']?@', $tokenInfo['content']) === 1) {
      return $ptr;
    }
  }
  return false;
}