Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentAlignmentSniff.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 * Drupal_Sniffs_Commenting_EmptyCatchCommentSniff. | 3 * \Drupal\Sniffs\Commenting\DocCommentAlignmentSniff. |
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 | 9 |
10 namespace Drupal\Sniffs\Commenting; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Sniffs\Sniff; | |
14 use PHP_CodeSniffer\Util\Tokens; | |
15 | |
10 /** | 16 /** |
11 * Largely copied from Squiz_Sniffs_Commenting_DocCommentAlignmentSniff to also | 17 * Largely copied from |
18 * \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff to also | |
12 * handle the "var" keyword. See | 19 * handle the "var" keyword. See |
13 * https://github.com/squizlabs/PHP_CodeSniffer/pull/1212 | 20 * https://github.com/squizlabs/PHP_CodeSniffer/pull/1212 |
14 * | 21 * |
15 * @category PHP | 22 * @category PHP |
16 * @package PHP_CodeSniffer | 23 * @package PHP_CodeSniffer |
17 * @link http://pear.php.net/package/PHP_CodeSniffer | 24 * @link http://pear.php.net/package/PHP_CodeSniffer |
18 */ | 25 */ |
19 class Drupal_Sniffs_Commenting_DocCommentAlignmentSniff implements PHP_CodeSniffer_Sniff | 26 class DocCommentAlignmentSniff implements Sniff |
20 { | 27 { |
21 | 28 |
22 | 29 |
23 /** | 30 /** |
24 * Returns an array of tokens this test wants to listen for. | 31 * Returns an array of tokens this test wants to listen for. |
33 | 40 |
34 | 41 |
35 /** | 42 /** |
36 * Processes this test, when one of its tokens is encountered. | 43 * Processes this test, when one of its tokens is encountered. |
37 * | 44 * |
38 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | 45 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. |
39 * @param int $stackPtr The position of the current token | 46 * @param int $stackPtr The position of the current token |
40 * in the stack passed in $tokens. | 47 * in the stack passed in $tokens. |
41 * | 48 * |
42 * @return void | 49 * @return void |
43 */ | 50 */ |
44 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | 51 public function process(File $phpcsFile, $stackPtr) |
45 { | 52 { |
46 $tokens = $phpcsFile->getTokens(); | 53 $tokens = $phpcsFile->getTokens(); |
47 | 54 |
48 // We are only interested in function/class/interface doc block comments. | 55 // We are only interested in function/class/interface doc block comments. |
49 $ignore = PHP_CodeSniffer_Tokens::$emptyTokens; | 56 $ignore = Tokens::$emptyTokens; |
50 if ($phpcsFile->tokenizerType === 'JS') { | 57 if ($phpcsFile->tokenizerType === 'JS') { |
51 $ignore[] = T_EQUAL; | 58 $ignore[] = T_EQUAL; |
52 $ignore[] = T_STRING; | 59 $ignore[] = T_STRING; |
53 $ignore[] = T_OBJECT_OPERATOR; | 60 $ignore[] = T_OBJECT_OPERATOR; |
54 } | 61 } |
69 T_VAR => true, | 76 T_VAR => true, |
70 ); | 77 ); |
71 | 78 |
72 if (isset($ignore[$tokens[$nextToken]['code']]) === false) { | 79 if (isset($ignore[$tokens[$nextToken]['code']]) === false) { |
73 // Could be a file comment. | 80 // Could be a file comment. |
74 $prevToken = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true); | 81 $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); |
75 if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) { | 82 if ($tokens[$prevToken]['code'] !== T_OPEN_TAG) { |
76 return; | 83 return; |
77 } | 84 } |
78 } | 85 } |
79 | 86 |