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
|
|
|
// @codeCoverageIgnoreStart |
15
|
|
|
if (class_exists('Generic_Sniffs_Commenting_DocCommentSniff', true) === false) { |
16
|
|
|
$error = 'Class Generic_Sniffs_Commenting_DocCommentSniff not found'; |
17
|
|
|
throw new PHP_CodeSniffer_Exception($error); |
18
|
|
|
} |
19
|
|
|
// @codeCoverageIgnoreEnd |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Ensures doc blocks follow basic formatting. |
23
|
|
|
* |
24
|
|
|
* @category PHP |
25
|
|
|
* @package PHP_CodeSniffer |
26
|
|
|
* @author Alexander Obuhovich <[email protected]> |
27
|
|
|
* @license https://github.com/aik099/CodingStandard/blob/master/LICENSE BSD 3-Clause |
28
|
|
|
* @link https://github.com/aik099/CodingStandard |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
class CodingStandard_Sniffs_Commenting_DocCommentSniff extends Generic_Sniffs_Commenting_DocCommentSniff |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Processes this test, when one of its tokens is encountered. |
36
|
|
|
* |
37
|
|
|
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
38
|
|
|
* @param int $stackPtr The position of the current token |
39
|
|
|
* in the stack passed in $tokens. |
40
|
|
|
* |
41
|
|
|
* @return void |
42
|
|
|
*/ |
43
|
1 |
|
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
44
|
|
|
{ |
45
|
1 |
|
$tokens = $phpcsFile->getTokens(); |
46
|
1 |
|
$commentEnd = $phpcsFile->findNext(T_DOC_COMMENT_CLOSE_TAG, ($stackPtr + 1)); |
47
|
1 |
|
$commentStart = $tokens[$commentEnd]['comment_opener']; |
48
|
|
|
|
49
|
1 |
|
if ($tokens[$commentStart]['line'] === $tokens[$commentEnd]['line']) { |
50
|
1 |
|
$commentText = $phpcsFile->getTokensAsString($commentStart, ($commentEnd - $commentStart + 1)); |
51
|
|
|
|
52
|
1 |
|
if (strpos($commentText, '@var') !== false || strpos($commentText, '@type') !== false) { |
53
|
|
|
// Skip inline block comments with variable type definition. |
54
|
1 |
|
return; |
55
|
|
|
} |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
parent::process($phpcsFile, $stackPtr); |
59
|
|
|
|
60
|
1 |
|
}//end process() |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
}//end class |
64
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.