1 | <?php |
||
26 | class RequiredDocBlockSniff extends AbstractSniff |
||
27 | { |
||
28 | use DocPosProviderTrait; |
||
29 | |||
30 | /** |
||
31 | * The error code for missing doc blocks. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public const CODE_MISSING_DOC_BLOCK_PREFIX = 'MissingDocBlock'; |
||
36 | |||
37 | /** |
||
38 | * The error code for the inline block. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | public const CODE_NO_MULTI_LINE_DOC_BLOCK_PREFIX = 'NoMultiLineDocBlock'; |
||
43 | |||
44 | /** |
||
45 | * The message for missing doc blocks. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private const MESSAGE_MISSING_DOC_BLOCK = 'Please provide a doc block for your %s.'; |
||
50 | |||
51 | /** |
||
52 | * The error message for the inline block. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private const MESSAGE_NO_MULTI_LINE_DOC_BLOCK_PREFIX = 'Please provide a multi line doc block for your %s.'; |
||
57 | |||
58 | /** |
||
59 | * Maps the registered tokens to a readable key. |
||
60 | * |
||
61 | * @var array |
||
62 | */ |
||
63 | private $registeredTokens = [ |
||
64 | T_CLASS => 'Class', |
||
65 | T_CONST => 'Constant', |
||
66 | T_INTERFACE => 'Interface', |
||
67 | T_FUNCTION => 'Function', |
||
68 | T_TRAIT => 'Trait', |
||
69 | T_VARIABLE => 'Variable' |
||
70 | ]; |
||
71 | |||
72 | /** |
||
73 | * Ignore normal variables for this sniff. |
||
74 | * |
||
75 | * @return bool |
||
76 | */ |
||
77 | protected function areRequirementsMet(): bool |
||
81 | |||
82 | /** |
||
83 | * Checks for a missing doc block and throws an error if the doc is missing. |
||
84 | * |
||
85 | * @throws CodeWarning |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | private function checkAndRegisterMissingDocBlock(): void |
||
103 | |||
104 | /** |
||
105 | * Checks and registers a multi line error. |
||
106 | * |
||
107 | * @throws CodeWarning |
||
108 | * |
||
109 | * @return void |
||
110 | */ |
||
111 | private function checkAndRegisterNoMultiLine(): void |
||
129 | |||
130 | /** |
||
131 | * Returns the name for the token. |
||
132 | * |
||
133 | * @return string |
||
134 | */ |
||
135 | private function getTokenName(): string |
||
139 | |||
140 | /** |
||
141 | * Processes the token. |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | protected function processToken(): void |
||
154 | |||
155 | /** |
||
156 | * Register for all tokens which require a php doc block for us. |
||
157 | * |
||
158 | * @return array |
||
159 | */ |
||
160 | public function register(): array |
||
164 | |||
165 | /** |
||
166 | * Resets the doc comment position after this test. |
||
167 | * |
||
168 | * @return void |
||
169 | */ |
||
170 | protected function tearDown(): void |
||
174 | } |
||
175 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: