1 | <?php |
||
23 | final class VarPropertyCommentSniff extends PHP_CodeSniffer_Standards_AbstractVariableSniff |
||
24 | { |
||
25 | |||
26 | /** |
||
27 | * @param PHP_CodeSniffer_File $file |
||
28 | * @param int $position |
||
29 | */ |
||
30 | 1 | protected function processMemberVar(PHP_CodeSniffer_File $file, $position) |
|
31 | { |
||
32 | 1 | $commentString = $this->getPropertyComment($file, $position); |
|
33 | |||
34 | 1 | if (strpos($commentString, '@var') !== FALSE) { |
|
35 | 1 | return; |
|
36 | } |
||
37 | |||
38 | 1 | $file->addError('Property should have docblock comment.', $position); |
|
39 | 1 | } |
|
40 | |||
41 | |||
42 | /** |
||
43 | * @param PHP_CodeSniffer_File $file |
||
44 | * @param int $position |
||
45 | */ |
||
46 | 1 | protected function processVariable(PHP_CodeSniffer_File $file, $position) |
|
49 | |||
50 | |||
51 | /** |
||
52 | * @param PHP_CodeSniffer_File $file |
||
53 | * @param int $position |
||
54 | */ |
||
55 | protected function processVariableInString(PHP_CodeSniffer_File $file, $position) |
||
58 | |||
59 | |||
60 | 1 | private function getPropertyComment(PHP_CodeSniffer_File $file, int $position) : string |
|
82 | |||
83 | } |
||
84 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.