|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Ensures doc blocks follow basic formatting. |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5 |
|
6
|
|
|
* |
|
7
|
|
|
* @category PHP |
|
8
|
|
|
* @package PHP_CodeSniffer |
|
9
|
|
|
* @author Alexander Obuhovich <[email protected]> |
|
10
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
|
11
|
|
|
* @link https://github.com/aik099/CodingStandard |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace CodingStandard\Sniffs\Commenting; |
|
15
|
|
|
|
|
16
|
|
|
use PHP_CodeSniffer\Files\File; |
|
17
|
|
|
use PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff as Generic_DocCommentSniff; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Ensures doc blocks follow basic formatting. |
|
21
|
|
|
* |
|
22
|
|
|
* @category PHP |
|
23
|
|
|
* @package PHP_CodeSniffer |
|
24
|
|
|
* @author Alexander Obuhovich <[email protected]> |
|
25
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
|
26
|
|
|
* @link https://github.com/aik099/CodingStandard |
|
27
|
|
|
*/ |
|
28
|
|
|
|
|
29
|
|
|
class DocCommentSniff extends Generic_DocCommentSniff |
|
30
|
|
|
{ |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Processes this test, when one of its tokens is encountered. |
|
34
|
|
|
* |
|
35
|
|
|
* @param File $phpcsFile The file being scanned. |
|
36
|
|
|
* @param int $stackPtr The position of the current token in the |
|
37
|
|
|
* stack passed in $tokens. |
|
38
|
|
|
* |
|
39
|
|
|
* @return void |
|
40
|
|
|
*/ |
|
41
|
1 |
|
public function process(File $phpcsFile, $stackPtr) |
|
42
|
|
|
{ |
|
43
|
1 |
|
$tokens = $phpcsFile->getTokens(); |
|
44
|
1 |
|
$commentEnd = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1)); |
|
45
|
1 |
|
$commentStart = $tokens[$commentEnd]['comment_opener']; |
|
46
|
|
|
|
|
47
|
1 |
|
if ($tokens[$commentStart]['line'] === $tokens[$commentEnd]['line']) { |
|
48
|
1 |
|
$commentText = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1)); |
|
49
|
|
|
|
|
50
|
1 |
|
if (strpos($commentText, '@var') !== false || strpos($commentText, '@type') !== false) { |
|
51
|
|
|
// Skip inline block comments with variable type definition. |
|
52
|
1 |
|
return; |
|
53
|
|
|
} |
|
54
|
1 |
|
} |
|
55
|
|
|
|
|
56
|
1 |
|
if ($this->isInheritDoc($phpcsFile, $commentStart) === true) { |
|
57
|
1 |
|
return; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
parent::process($phpcsFile, $stackPtr); |
|
61
|
|
|
}//end process() |
|
62
|
|
|
|
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Is the comment an inheritdoc? |
|
66
|
|
|
* |
|
67
|
|
|
* @param File $phpcsFile The file being scanned. |
|
68
|
|
|
* @param int $commentStart The position in the stack where the comment started. |
|
69
|
|
|
* |
|
70
|
|
|
* @return bool |
|
71
|
|
|
*/ |
|
72
|
|
|
protected function isInheritDoc(File $phpcsFile, $commentStart) |
|
73
|
|
|
{ |
|
74
|
|
|
$tokens = $phpcsFile->getTokens(); |
|
75
|
|
|
|
|
76
|
|
|
$commentEnd = $tokens[$commentStart]['comment_closer']; |
|
77
|
|
|
$commentText = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1)); |
|
78
|
|
|
|
|
79
|
|
|
return stripos($commentText, '@inheritdoc') !== false; |
|
80
|
|
|
}// end isInheritDoc() |
|
81
|
|
|
}//end class |
|
82
|
|
|
|