Chris@0
|
1 <?php
|
Chris@0
|
2 /**
|
Chris@0
|
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@0
|
10 /**
|
Chris@0
|
11 * Checks that ['und'] is not used, should be LANGUAGE_NONE.
|
Chris@0
|
12 *
|
Chris@0
|
13 * @category PHP
|
Chris@0
|
14 * @package PHP_CodeSniffer
|
Chris@0
|
15 * @link http://pear.php.net/package/PHP_CodeSniffer
|
Chris@0
|
16 */
|
Chris@0
|
17 class DrupalPractice_Sniffs_General_LanguageNoneSniff implements PHP_CodeSniffer_Sniff
|
Chris@0
|
18 {
|
Chris@0
|
19
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Returns an array of tokens this test wants to listen for.
|
Chris@0
|
23 *
|
Chris@0
|
24 * @return array
|
Chris@0
|
25 */
|
Chris@0
|
26 public function register()
|
Chris@0
|
27 {
|
Chris@0
|
28 return array(
|
Chris@0
|
29 T_OPEN_SQUARE_BRACKET,
|
Chris@0
|
30 T_OPEN_SHORT_ARRAY,
|
Chris@0
|
31 );
|
Chris@0
|
32
|
Chris@0
|
33 }//end register()
|
Chris@0
|
34
|
Chris@0
|
35
|
Chris@0
|
36 /**
|
Chris@0
|
37 * Processes this test, when one of its tokens is encountered.
|
Chris@0
|
38 *
|
Chris@0
|
39 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed.
|
Chris@0
|
40 * @param int $stackPtr The position of the current token
|
Chris@0
|
41 * in the stack passed in $tokens.
|
Chris@0
|
42 *
|
Chris@0
|
43 * @return void
|
Chris@0
|
44 */
|
Chris@0
|
45 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
|
Chris@0
|
46 {
|
Chris@0
|
47 $sequence = $phpcsFile->getTokensAsString($stackPtr, 3);
|
Chris@0
|
48 if ($sequence === "['und']" || $sequence === '["und"]') {
|
Chris@0
|
49 $warning = "Are you accessing field values here? Then you should use LANGUAGE_NONE instead of 'und'";
|
Chris@0
|
50 $phpcsFile->addWarning($warning, ($stackPtr + 1), 'Und');
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 }//end process()
|
Chris@0
|
54
|
Chris@0
|
55
|
Chris@0
|
56 }//end class
|