1 | <?php declare(strict_types = 1); |
||
8 | class FinalPrivateSniff implements PHP_CodeSniffer_Sniff |
||
9 | { |
||
10 | /** |
||
11 | * Returns the token types that this sniff is interested in. |
||
12 | * @return array |
||
13 | */ |
||
14 | public function register(): array |
||
18 | |||
19 | /** |
||
20 | * Is the class marked as final? |
||
21 | * @var boolean |
||
22 | */ |
||
23 | protected $classIsMarkedFinal = false; |
||
24 | |||
25 | /** |
||
26 | * List of protected methods found. |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $protectedMethods = []; |
||
30 | |||
31 | /** |
||
32 | * List of protected variables found. |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $protectedVariables = []; |
||
36 | |||
37 | /** |
||
38 | * Processes the tokens that this sniff is interested in. |
||
39 | * |
||
40 | * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
||
41 | * @param int $stackPtr The position in the stack where |
||
42 | * the token was found. |
||
43 | * @return void |
||
44 | * @SuppressWarnings(PHPMD.UnusedLocalVariable) |
||
45 | */ |
||
46 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
56 | |||
57 | /** |
||
58 | * Handle the incoming token. |
||
59 | * @param array $tokens List of tokens. |
||
60 | * @param integer $index Current token index. |
||
61 | * @return void |
||
62 | */ |
||
63 | protected function handleToken($tokens, $index) |
||
82 | |||
83 | /** |
||
84 | * Handles found protected method or variable within |
||
85 | * a final class. |
||
86 | * @param array $tokens List of tokens. |
||
87 | * @param integer $index Current token index. |
||
88 | * @return void |
||
89 | */ |
||
90 | protected function handleFoundProtectedElement($tokens, $index) |
||
103 | |||
104 | /** |
||
105 | * Handle any errors. |
||
106 | * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
||
107 | * @param int $stackPtr The position in the stack where. |
||
108 | * @return void |
||
109 | */ |
||
110 | protected function handleErrors($phpcsFile, $stackPtr) |
||
120 | |||
121 | /** |
||
122 | * Add a protected method found error. |
||
123 | * @param string $method Name of the method found. |
||
124 | * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
||
125 | * @param int $stackPtr The position in the stack where. |
||
126 | * @return void |
||
127 | */ |
||
128 | protected function handleProtectedMethod($method, $phpcsFile, $stackPtr) |
||
132 | |||
133 | /** |
||
134 | * Add a protected variable found error. |
||
135 | * @param string $variable Name of the variable found. |
||
136 | * @param PHP_CodeSniffer_File $phpcsFile The file where the token was found. |
||
137 | * @param int $stackPtr The position in the stack where. |
||
138 | * @return void |
||
139 | */ |
||
140 | protected function handleProtectedVariable($variable, $phpcsFile, $stackPtr) |
||
144 | } |
||
145 |