1 | <?php |
||
16 | class SpaceAfterDeclareSniff implements Sniff |
||
17 | { |
||
18 | /** |
||
19 | * Error message when no whitespace is found. |
||
20 | */ |
||
21 | public const MESSAGE_NO_WHITESPACE_FOUND = 'There is no whitespace after declare-statement.'; |
||
22 | |||
23 | /** |
||
24 | * There MUST be one empty line after declare-statement. |
||
25 | */ |
||
26 | public const CODE_NO_WHITESPACE_FOUND = 'NoWhitespaceFound'; |
||
27 | |||
28 | /** |
||
29 | * Error message when more than one whitespaces are found. |
||
30 | */ |
||
31 | public const MESSAGE_MUCH_WHITESPACE_FOUND = 'There are more than one whitespaces after declare-statement.'; |
||
32 | |||
33 | /** |
||
34 | * THERE MUST be just one single line after the declare statement. |
||
35 | */ |
||
36 | public const CODE_MUCH_WHITESPACE_FOUND = 'MuchWhitespaceFound'; |
||
37 | |||
38 | /** |
||
39 | * Error message when blank lines in a group are found. |
||
40 | */ |
||
41 | public const MESSAGE_GROUP_BLANK_LINE_FOUND = 'Multpile declare-statements should be grouped without a blank line.'; |
||
42 | |||
43 | /** |
||
44 | * Multiple declare-statements SHOULD be grouped without a blank line. |
||
45 | */ |
||
46 | public const CODE_GROUP_BLANK_LINE_FOUND = 'GroupBlankLineFound'; |
||
47 | |||
48 | /** |
||
49 | * Registers the tokens that this sniff wants to listen for. |
||
50 | * |
||
51 | * @return int[] List of tokens to listen for |
||
52 | 5 | */ |
|
53 | public function register(): array |
||
59 | |||
60 | /** |
||
61 | * Called when one of the token types that this sniff is listening for is found. |
||
62 | * |
||
63 | * @phpcsSuppress SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint |
||
64 | * |
||
65 | * @param File $phpcsFile The PHP_CodeSniffer file where the token was found. |
||
66 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. |
||
67 | 4 | * |
|
68 | * @return void Optionally returns a stack pointer. |
||
69 | 4 | */ |
|
70 | public function process(File $phpcsFile, $stackPtr): void |
||
117 | |||
118 | 3 | /** |
|
119 | * Handles when no whitespace is found. |
||
120 | * |
||
121 | * @param File $phpcsFile The php cs file |
||
122 | * @param int $semicolonPtr Pointer to the semicolon token |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | private function handleNoWhitespaceFound(File $phpcsFile, int $semicolonPtr): void |
||
140 | |||
141 | /** |
||
142 | 1 | * Handles when more than one whitespaces are found. |
|
143 | 1 | * |
|
144 | 1 | * @param File $phpcsFile The php cs file |
|
145 | 1 | * @param int $semicolonPtr Pointer to the semicolon |
|
146 | * @param int $secondSpacePtr Pointer to the second space |
||
147 | 1 | * @param int $nextNonSpacePtr Pointer to the next non space token |
|
148 | * |
||
149 | 1 | * @return void |
|
150 | */ |
||
151 | private function handleMuchWhitespacesFound( |
||
171 | |||
172 | /** |
||
173 | * Handles blank lines found in declare group. |
||
174 | * |
||
175 | * @param File $phpcsFile The php cs file |
||
176 | * @param int $semicolonPtr Pointer to the semicolon |
||
177 | * @param int $secondSpacePtr Pointer to the second space |
||
178 | * @param int $nextNonSpacePtr Pointer to the next non space token |
||
179 | * |
||
180 | * @return void |
||
181 | */ |
||
182 | private function handleBlankLineInGroup( |
||
202 | } |
||
203 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.