comparison vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalDefineSniff.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_GlobalDefineSniff 3 * \DrupalPractice\Sniffs\Constants\GlobalDefineSniff
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 PHP_CodeSniffer\Files\File;
13 use Drupal\Sniffs\Semantics\FunctionCall;
14 use DrupalPractice\Project;
9 15
10 /** 16 /**
11 * Checks that global define() constants are not used in modules in Drupal 8. 17 * Checks that global define() constants are not used in modules in Drupal 8.
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_GlobalDefineSniff extends Drupal_Sniffs_Semantics_FunctionCall 23 class GlobalDefineSniff extends FunctionCall
18 { 24 {
19 25
20 26
21 /** 27 /**
22 * Returns an array of function names this test wants to listen for. 28 * Returns an array of function names this test wants to listen for.
31 37
32 38
33 /** 39 /**
34 * Processes this function call. 40 * Processes this function call.
35 * 41 *
36 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. 42 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
37 * @param int $stackPtr The position of the function call in 43 * @param int $stackPtr The position of the function call in
38 * the stack. 44 * the stack.
39 * @param int $openBracket The position of the opening 45 * @param int $openBracket The position of the opening
40 * parenthesis in the stack. 46 * parenthesis in the stack.
41 * @param int $closeBracket The position of the closing 47 * @param int $closeBracket The position of the closing
42 * parenthesis in the stack. 48 * parenthesis in the stack.
43 * 49 *
44 * @return void 50 * @return void
45 */ 51 */
46 public function processFunctionCall( 52 public function processFunctionCall(
47 PHP_CodeSniffer_File $phpcsFile, 53 File $phpcsFile,
48 $stackPtr, 54 $stackPtr,
49 $openBracket, 55 $openBracket,
50 $closeBracket 56 $closeBracket
51 ) { 57 ) {
52 $tokens = $phpcsFile->getTokens(); 58 $tokens = $phpcsFile->getTokens();
54 // Only check constants in the global scope in module files. 60 // Only check constants in the global scope in module files.
55 if (empty($tokens[$stackPtr]['conditions']) === false || substr($phpcsFile->getFilename(), -7) !== '.module') { 61 if (empty($tokens[$stackPtr]['conditions']) === false || substr($phpcsFile->getFilename(), -7) !== '.module') {
56 return; 62 return;
57 } 63 }
58 64
59 $coreVersion = DrupalPractice_Project::getCoreVersion($phpcsFile); 65 $coreVersion = Project::getCoreVersion($phpcsFile);
60 if ($coreVersion !== '8.x') { 66 if ($coreVersion !== '8.x') {
61 return; 67 return;
62 } 68 }
63 69
64 // Allow constants if they are deprecated. 70 // Allow constants if they are deprecated.