Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.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 * DrupalPractice_Sniffs_Constants_GlobalConstantSniff | 3 * \DrupalPractice\Sniffs\Constants\GlobalConstantSniff |
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 DrupalPractice\Sniffs\Constants; | |
11 | |
12 use DrupalPractice\Project; | |
13 use PHP_CodeSniffer\Files\File; | |
14 use PHP_CodeSniffer\Sniffs\Sniff; | |
9 | 15 |
10 /** | 16 /** |
11 * Checks that globally defined constants are not used in Drupal 8 and higher. | 17 * Checks that globally defined constants are not used in Drupal 8 and higher. |
12 * | 18 * |
13 * @category PHP | 19 * @category PHP |
14 * @package PHP_CodeSniffer | 20 * @package PHP_CodeSniffer |
15 * @link http://pear.php.net/package/PHP_CodeSniffer | 21 * @link http://pear.php.net/package/PHP_CodeSniffer |
16 */ | 22 */ |
17 class DrupalPractice_Sniffs_Constants_GlobalConstantSniff implements PHP_CodeSniffer_Sniff | 23 class GlobalConstantSniff implements Sniff |
18 { | 24 { |
19 | 25 |
20 | 26 |
21 /** | 27 /** |
22 * Returns an array of tokens this test wants to listen for. | 28 * Returns an array of tokens this test wants to listen for. |
31 | 37 |
32 | 38 |
33 /** | 39 /** |
34 * Processes this test, when one of its tokens is encountered. | 40 * Processes this test, when one of its tokens is encountered. |
35 * | 41 * |
36 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. | 42 * @param \PHP_CodeSniffer\Files\File $phpcsFile The current file being processed. |
37 * @param int $stackPtr The position of the current token | 43 * @param int $stackPtr The position of the current token |
38 * in the stack passed in $tokens. | 44 * in the stack passed in $tokens. |
39 * | 45 * |
40 * @return void | 46 * @return void |
41 */ | 47 */ |
42 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 48 public function process(File $phpcsFile, $stackPtr) |
43 { | 49 { |
44 $tokens = $phpcsFile->getTokens(); | 50 $tokens = $phpcsFile->getTokens(); |
45 | 51 |
46 // Only check constants in the global scope. | 52 // Only check constants in the global scope. |
47 if (empty($tokens[$stackPtr]['conditions']) === false) { | 53 if (empty($tokens[$stackPtr]['conditions']) === false) { |
48 return; | 54 return; |
49 } | 55 } |
50 | 56 |
51 $coreVersion = DrupalPractice_Project::getCoreVersion($phpcsFile); | 57 $coreVersion = Project::getCoreVersion($phpcsFile); |
52 if ($coreVersion !== '8.x') { | 58 if ($coreVersion !== '8.x') { |
53 return; | 59 return; |
54 } | 60 } |
55 | 61 |
56 // Allow constants if they are deprecated. | 62 // Allow constants if they are deprecated. |