Mercurial > hg > isophonics-drupal-site
annotate vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/LanguageNoneSniff.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 /** |
Chris@17 | 3 * \DrupalPractice\Sniffs\General\LanguageNoneSniff |
Chris@0 | 4 * |
Chris@0 | 5 * @category PHP |
Chris@0 | 6 * @package PHP_CodeSniffer |
Chris@0 | 7 * @link http://pear.php.net/package/PHP_CodeSniffer |
Chris@0 | 8 */ |
Chris@0 | 9 |
Chris@17 | 10 namespace DrupalPractice\Sniffs\General; |
Chris@17 | 11 |
Chris@17 | 12 use PHP_CodeSniffer\Files\File; |
Chris@17 | 13 use PHP_CodeSniffer\Sniffs\Sniff; |
Chris@17 | 14 |
Chris@0 | 15 /** |
Chris@0 | 16 * Checks that ['und'] is not used, should be LANGUAGE_NONE. |
Chris@0 | 17 * |
Chris@0 | 18 * @category PHP |
Chris@0 | 19 * @package PHP_CodeSniffer |
Chris@0 | 20 * @link http://pear.php.net/package/PHP_CodeSniffer |
Chris@0 | 21 */ |
Chris@17 | 22 class LanguageNoneSniff implements Sniff |
Chris@0 | 23 { |
Chris@0 | 24 |
Chris@0 | 25 |
Chris@0 | 26 /** |
Chris@0 | 27 * Returns an array of tokens this test wants to listen for. |
Chris@0 | 28 * |
Chris@0 | 29 * @return array |
Chris@0 | 30 */ |
Chris@0 | 31 public function register() |
Chris@0 | 32 { |
Chris@0 | 33 return array( |
Chris@0 | 34 T_OPEN_SQUARE_BRACKET, |
Chris@0 | 35 T_OPEN_SHORT_ARRAY, |
Chris@0 | 36 ); |
Chris@0 | 37 |
Chris@0 | 38 }//end register() |
Chris@0 | 39 |
Chris@0 | 40 |
Chris@0 | 41 /** |
Chris@0 | 42 * Processes this test, when one of its tokens is encountered. |
Chris@0 | 43 * |
Chris@17 | 44 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
Chris@17 | 45 * @param int $stackPtr The position of the function |
Chris@17 | 46 * name in the stack. |
Chris@0 | 47 * |
Chris@0 | 48 * @return void |
Chris@0 | 49 */ |
Chris@17 | 50 public function process(File $phpcsFile, $stackPtr) |
Chris@0 | 51 { |
Chris@0 | 52 $sequence = $phpcsFile->getTokensAsString($stackPtr, 3); |
Chris@0 | 53 if ($sequence === "['und']" || $sequence === '["und"]') { |
Chris@0 | 54 $warning = "Are you accessing field values here? Then you should use LANGUAGE_NONE instead of 'und'"; |
Chris@0 | 55 $phpcsFile->addWarning($warning, ($stackPtr + 1), 'Und'); |
Chris@0 | 56 } |
Chris@0 | 57 |
Chris@0 | 58 }//end process() |
Chris@0 | 59 |
Chris@0 | 60 |
Chris@0 | 61 }//end class |