1 | <?php declare(strict_types = 1); |
||
8 | class PropertyDeclarationSniff implements PHP_CodeSniffer_Sniff |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * The decalred member variables in the class. |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $memberVars = []; |
||
16 | |||
17 | /** |
||
18 | * The referenced member variables in the class. |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $referencedMemberVars = []; |
||
22 | |||
23 | /** |
||
24 | * Visibility Tokens. |
||
25 | * @var array |
||
26 | */ |
||
27 | protected $visibilityTokens = ['T_PRIVATE', 'T_PUBLIC', 'T_PROTECTED']; |
||
28 | |||
29 | /** |
||
30 | * Holds the value if the class is extended or not. |
||
31 | * @var boolean |
||
32 | */ |
||
33 | protected $isExtendedClass = false; |
||
34 | |||
35 | /** |
||
36 | * Returns the token types that this sniff is interested in. |
||
37 | * @return array |
||
38 | */ |
||
39 | public function register(): array |
||
43 | |||
44 | /** |
||
45 | * Processes the tokens that this sniff is interested in. |
||
46 | * |
||
47 | * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
||
48 | * @param int $stackPtr The position in the stack where |
||
49 | * the token was found. |
||
50 | * @return void |
||
51 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
||
52 | */ |
||
53 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
68 | |||
69 | /** |
||
70 | * Handle the incoming token. |
||
71 | * @param array $tokens List of tokens. |
||
72 | * @param integer $index Current token index. |
||
73 | * @return void |
||
74 | */ |
||
75 | protected function handleToken($tokens, $index) |
||
95 | |||
96 | /** |
||
97 | * Determines if the provided token is a visiblity token. |
||
98 | * @param array $token Token data. |
||
99 | * @return boolean |
||
100 | */ |
||
101 | protected function isVisibilityToken($token): bool |
||
105 | |||
106 | /** |
||
107 | * Handles the logic for a visiblity type token. |
||
108 | * @param array $tokens List of tokens. |
||
109 | * @param integer $index Current token index. |
||
110 | * @return void |
||
111 | */ |
||
112 | protected function handleVisibilityToken($tokens, $index) |
||
120 | |||
121 | /** |
||
122 | * Handles the logic for an object operator token. |
||
123 | * @param array $tokens List of tokens. |
||
124 | * @param integer $index Current token index. |
||
125 | * @return void |
||
126 | */ |
||
127 | protected function handleObjectOperatorToken($tokens, $index) |
||
143 | |||
144 | /** |
||
145 | * If the class is extended from another class then a warning is produced. |
||
146 | * Otherwise an error is produced. |
||
147 | * @param string $undeclaredVariable Name of the undeclared member variable. |
||
148 | * @param PHP_CodeSniffer_File $phpcsFile PHP Code Sniffer File. |
||
149 | * @param integer $index Index of where the undeclared variable was found in the file. |
||
150 | * @return void |
||
151 | */ |
||
152 | protected function handleError($undeclaredVariable, $phpcsFile, $index) |
||
160 | } |
||
161 |