1 | <?php |
||
17 | class SpaceAfterDeclareSniff implements PHP_CodeSniffer_Sniff |
||
18 | { |
||
19 | /** |
||
20 | * Error message when no whitespace is found. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | const MESSAGE_NO_WHITESPACE_FOUND = 'There is no whitespace after declare-statement.'; |
||
25 | |||
26 | /** |
||
27 | * Code when no whitespace is found. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | const CODE_NO_WHITESPACE_FOUND = 'NoWhitespaceFound'; |
||
32 | |||
33 | /** |
||
34 | * Error message when more than one whitespaces are found. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | const MESSAGE_MUCH_WHITESPACE_FOUND = 'There are more than one whitespaces after declare-statement.'; |
||
39 | |||
40 | /** |
||
41 | * Code when more than one whitespaces are found. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | const CODE_MUCH_WHITESPACE_FOUND = 'MuchWhitespaceFound'; |
||
46 | |||
47 | /** |
||
48 | * Registers the tokens that this sniff wants to listen for. |
||
49 | * |
||
50 | * @return int[] |
||
51 | */ |
||
52 | 3 | public function register() |
|
58 | |||
59 | /** |
||
60 | * Called when one of the token types that this sniff is listening for |
||
61 | * is found. |
||
62 | * |
||
63 | * @param PHP_CodeSniffer_File $phpcsFile The PHP_CodeSniffer file where the token was found. |
||
64 | * @param int $stackPtr The position in the PHP_CodeSniffer file's token stack where the token was found. |
||
65 | * |
||
66 | * @return void|int Optionally returns a stack pointer. |
||
67 | */ |
||
68 | 3 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
|
92 | |||
93 | /** |
||
94 | * Handles when no whitespace is found. |
||
95 | * |
||
96 | * @param PHP_CodeSniffer_File $phpcsFile |
||
97 | * @param int $semicolonPtr |
||
98 | * |
||
99 | * @return void |
||
100 | */ |
||
101 | 2 | private function handleNoWhitespaceFound(PHP_CodeSniffer_File $phpcsFile, $semicolonPtr) |
|
115 | |||
116 | /** |
||
117 | * Handles when more than one whitespaces are found. |
||
118 | * |
||
119 | * @param PHP_CodeSniffer_File $phpcsFile |
||
120 | * @param int $semicolonPtr |
||
121 | * @param int $secondSpacePtr |
||
122 | * @param int $nextNonSpacePtr |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 1 | private function handleMuchWhitespacesFound( |
|
146 | } |
||
147 |
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
.