Mercurial > hg > isophonics-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/DocCommentStarSniff.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 129ea1e6d783 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 /** | |
3 * Drupal_Sniffs_Commenting_DocCommentStarSniff | |
4 * | |
5 * @category PHP | |
6 * @package PHP_CodeSniffer | |
7 * @link http://pear.php.net/package/PHP_CodeSniffer | |
8 */ | |
9 | |
10 /** | |
11 * Checks that a doc comment block has a doc comment star on every line. | |
12 * | |
13 * @category PHP | |
14 * @package PHP_CodeSniffer | |
15 * @link http://pear.php.net/package/PHP_CodeSniffer | |
16 */ | |
17 class Drupal_Sniffs_Commenting_DocCommentStarSniff implements PHP_CodeSniffer_Sniff | |
18 { | |
19 | |
20 | |
21 /** | |
22 * Returns an array of tokens this test wants to listen for. | |
23 * | |
24 * @return array | |
25 */ | |
26 public function register() | |
27 { | |
28 return array(T_DOC_COMMENT_OPEN_TAG); | |
29 | |
30 }//end register() | |
31 | |
32 | |
33 /** | |
34 * Processes this test, when one of its tokens is encountered. | |
35 * | |
36 * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. | |
37 * @param int $stackPtr The position of the current token | |
38 * in the stack passed in $tokens. | |
39 * | |
40 * @return void | |
41 */ | |
42 public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
43 { | |
44 $tokens = $phpcsFile->getTokens(); | |
45 | |
46 $lastLineChecked = $tokens[$stackPtr]['line']; | |
47 for ($i = ($stackPtr + 1); $i < ($tokens[$stackPtr]['comment_closer'] - 1); $i++) { | |
48 // We are only interested in the beginning of the line. | |
49 if ($tokens[$i]['line'] === $lastLineChecked) { | |
50 continue; | |
51 } | |
52 | |
53 // The first token on the line must be a whitespace followed by a star. | |
54 if ($tokens[$i]['code'] === T_DOC_COMMENT_WHITESPACE) { | |
55 if ($tokens[($i + 1)]['code'] !== T_DOC_COMMENT_STAR) { | |
56 $error = 'Doc comment star missing'; | |
57 $fix = $phpcsFile->addFixableError($error, $i, 'StarMissing'); | |
58 if ($fix === true) { | |
59 if (strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) { | |
60 $phpcsFile->fixer->replaceToken($i, str_repeat(' ', $tokens[$stackPtr]['column'])."* \n"); | |
61 } else { | |
62 $phpcsFile->fixer->replaceToken($i, str_repeat(' ', $tokens[$stackPtr]['column']).'* '); | |
63 } | |
64 | |
65 // Ordering of lines might have changed - stop here. The | |
66 // fixer will restart the sniff if there are remaining fixes. | |
67 return; | |
68 } | |
69 } | |
70 } else if ($tokens[$i]['code'] !== T_DOC_COMMENT_STAR) { | |
71 $error = 'Doc comment star missing'; | |
72 $fix = $phpcsFile->addFixableError($error, $i, 'StarMissing'); | |
73 if ($fix === true) { | |
74 $phpcsFile->fixer->addContentBefore($i, str_repeat(' ', $tokens[$stackPtr]['column']).'* '); | |
75 } | |
76 }//end if | |
77 | |
78 $lastLineChecked = $tokens[$i]['line']; | |
79 }//end for | |
80 | |
81 }//end process() | |
82 | |
83 | |
84 }//end class |