Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/General/DescriptionTSniff.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_General_DescriptionTSniff | 3 * \DrupalPractice\Sniffs\General\DescriptionTSniff |
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\General; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Sniffs\Sniff; | |
9 | 14 |
10 /** | 15 /** |
11 * Checks that string values for #description in render arrays are translated. | 16 * Checks that string values for #description in render arrays are translated. |
12 * | 17 * |
13 * @category PHP | 18 * @category PHP |
14 * @package PHP_CodeSniffer | 19 * @package PHP_CodeSniffer |
15 * @link http://pear.php.net/package/PHP_CodeSniffer | 20 * @link http://pear.php.net/package/PHP_CodeSniffer |
16 */ | 21 */ |
17 class DrupalPractice_Sniffs_General_DescriptionTSniff implements PHP_CodeSniffer_Sniff | 22 class DescriptionTSniff implements Sniff |
18 { | 23 { |
19 | 24 |
20 | 25 |
21 /** | 26 /** |
22 * Returns an array of tokens this test wants to listen for. | 27 * Returns an array of tokens this test wants to listen for. |
31 | 36 |
32 | 37 |
33 /** | 38 /** |
34 * Processes this test, when one of its tokens is encountered. | 39 * Processes this test, when one of its tokens is encountered. |
35 * | 40 * |
36 * @param PHP_CodeSniffer_File $phpcsFile The current file being processed. | 41 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
37 * @param int $stackPtr The position of the current token | 42 * @param int $stackPtr The position of the function |
38 * in the stack passed in $tokens. | 43 * name in the stack. |
39 * | 44 * |
40 * @return void | 45 * @return void |
41 */ | 46 */ |
42 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 47 public function process(File $phpcsFile, $stackPtr) |
43 { | 48 { |
44 // Look for the string "#description". | 49 // Look for the string "#description". |
45 $tokens = $phpcsFile->getTokens(); | 50 $tokens = $phpcsFile->getTokens(); |
46 if ($tokens[$stackPtr]['content'] !== '"#description"' && $tokens[$stackPtr]['content'] !== "'#description'") { | 51 if ($tokens[$stackPtr]['content'] !== '"#description"' && $tokens[$stackPtr]['content'] !== "'#description'") { |
47 return; | 52 return; |
62 $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 1)); | 67 $stringToken = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, ($stackPtr + 1)); |
63 $content = strip_tags($tokens[$stringToken]['content']); | 68 $content = strip_tags($tokens[$stringToken]['content']); |
64 | 69 |
65 if (strlen($content) > 5) { | 70 if (strlen($content) > 5) { |
66 $warning = '#description values usually have to run through t() for translation'; | 71 $warning = '#description values usually have to run through t() for translation'; |
67 $phpcsFile->addWarning($warning, $stringToken); | 72 $phpcsFile->addWarning($warning, $stringToken, 'DescriptionT'); |
68 } | 73 } |
69 | 74 |
70 }//end process() | 75 }//end process() |
71 | 76 |
72 | 77 |