comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/InfoFiles/ClassFilesSniff.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2 /** 2 /**
3 * Drupal_Sniffs_InfoFiles_ClassFilesSniff. 3 * \Drupal\Sniffs\InfoFiles\ClassFilesSniff.
4 * 4 *
5 * @category PHP 5 * @category PHP
6 * @package PHP_CodeSniffer 6 * @package PHP_CodeSniffer
7 * @link http://pear.php.net/package/PHP_CodeSniffer 7 * @link http://pear.php.net/package/PHP_CodeSniffer
8 */ 8 */
9
10 namespace Drupal\Sniffs\InfoFiles;
11
12 use PHP_CodeSniffer\Files\File;
13 use PHP_CodeSniffer\Sniffs\Sniff;
9 14
10 /** 15 /**
11 * Checks files[] entries in info files. Only files containing classes/interfaces 16 * Checks files[] entries in info files. Only files containing classes/interfaces
12 * should be listed. 17 * should be listed.
13 * 18 *
14 * @category PHP 19 * @category PHP
15 * @package PHP_CodeSniffer 20 * @package PHP_CodeSniffer
16 * @link http://pear.php.net/package/PHP_CodeSniffer 21 * @link http://pear.php.net/package/PHP_CodeSniffer
17 */ 22 */
18 class Drupal_Sniffs_InfoFiles_ClassFilesSniff implements PHP_CodeSniffer_Sniff 23 class ClassFilesSniff implements Sniff
19 { 24 {
20 25
21 26
22 /** 27 /**
23 * Returns an array of tokens this test wants to listen for. 28 * Returns an array of tokens this test wants to listen for.
32 37
33 38
34 /** 39 /**
35 * Processes this test, when one of its tokens is encountered. 40 * Processes this test, when one of its tokens is encountered.
36 * 41 *
37 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 42 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
38 * @param int $stackPtr The position of the current token in the 43 * @param int $stackPtr The position of the current token in the
39 * stack passed in $tokens. 44 * stack passed in $tokens.
40 * 45 *
41 * @return int 46 * @return int
42 */ 47 */
43 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) 48 public function process(File $phpcsFile, $stackPtr)
44 { 49 {
45 // Only run this sniff once per info file. 50 // Only run this sniff once per info file.
46 $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4)); 51 $fileExtension = strtolower(substr($phpcsFile->getFilename(), -4));
47 if ($fileExtension !== 'info') { 52 if ($fileExtension !== 'info') {
48 return ($phpcsFile->numTokens + 1); 53 return ($phpcsFile->numTokens + 1);
85 90
86 91
87 /** 92 /**
88 * Helper function that returns the position of the key in the info file. 93 * Helper function that returns the position of the key in the info file.
89 * 94 *
90 * @param string $key Key name to search for. 95 * @param string $key Key name to search for.
91 * @param string $value Corresponding value to search for. 96 * @param string $value Corresponding value to search for.
92 * @param PHP_CodeSniffer_File $infoFile Info file to search in. 97 * @param \PHP_CodeSniffer\Files\File $infoFile Info file to search in.
93 * 98 *
94 * @return int|false Returns the stack position if the file name is found, false 99 * @return int|false Returns the stack position if the file name is found, false
95 * otherwise. 100 * otherwise.
96 */ 101 */
97 public static function getPtr($key, $value, PHP_CodeSniffer_File $infoFile) 102 public static function getPtr($key, $value, File $infoFile)
98 { 103 {
99 foreach ($infoFile->getTokens() as $ptr => $tokenInfo) { 104 foreach ($infoFile->getTokens() as $ptr => $tokenInfo) {
100 if (preg_match('@^[\s]*'.preg_quote($key).'[\s]*=[\s]*["\']?'.preg_quote($value).'["\']?@', $tokenInfo['content']) === 1) { 105 if (preg_match('@^[\s]*'.preg_quote($key).'[\s]*=[\s]*["\']?'.preg_quote($value).'["\']?@', $tokenInfo['content']) === 1) {
101 return $ptr; 106 return $ptr;
102 } 107 }