Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
17 | class PHPCompatibility_Sniffs_PHP_ValidIntegersSniff extends PHPCompatibility_Sniff |
||
|
|||
18 | { |
||
19 | protected $isLowPHPVersion = false; |
||
20 | |||
21 | /** |
||
22 | * Returns an array of tokens this test wants to listen for. |
||
23 | * |
||
24 | * @return array |
||
25 | */ |
||
26 | public function register() |
||
36 | |||
37 | |||
38 | /** |
||
39 | * Processes this test, when one of its tokens is encountered. |
||
40 | * |
||
41 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
42 | * @param int $stackPtr The position of the current token in |
||
43 | * the stack. |
||
44 | * |
||
45 | * @return void |
||
46 | */ |
||
47 | public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) |
||
100 | |||
101 | |||
102 | /** |
||
103 | * Could the current token an potentially be a binary integer ? |
||
104 | * |
||
105 | * @param array $tokens Token stack. |
||
106 | * @param int $stackPtr The current position in the token stack. |
||
107 | * |
||
108 | * @return bool |
||
109 | */ |
||
110 | private function couldBeBinaryInteger($tokens, $stackPtr) { |
||
126 | |||
127 | /** |
||
128 | * Is the current token an invalid binary integer ? |
||
129 | * |
||
130 | * @param array $tokens Token stack. |
||
131 | * @param int $stackPtr The current position in the token stack. |
||
132 | * |
||
133 | * @return bool |
||
134 | */ |
||
135 | private function isInvalidBinaryInteger($tokens, $stackPtr) { |
||
148 | |||
149 | /** |
||
150 | * Retrieve the content of the tokens which together look like a binary integer. |
||
151 | * |
||
152 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
153 | * @param array $tokens Token stack. |
||
154 | * @param int $stackPtr The position of the current token in |
||
155 | * the stack. |
||
156 | * |
||
157 | * @return string |
||
158 | */ |
||
159 | private function getBinaryInteger(PHP_CodeSniffer_File $phpcsFile, $tokens, $stackPtr) { |
||
172 | |||
173 | /** |
||
174 | * Is the current token an invalid octal integer ? |
||
175 | * |
||
176 | * @param array $tokens Token stack. |
||
177 | * @param int $stackPtr The current position in the token stack. |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | View Code Duplication | private function isInvalidOctalInteger($tokens, $stackPtr) { |
|
190 | |||
191 | /** |
||
192 | * Is the current token a hexidecimal numeric string ? |
||
193 | * |
||
194 | * @param array $tokens Token stack. |
||
195 | * @param int $stackPtr The current position in the token stack. |
||
196 | * |
||
197 | * @return bool |
||
198 | */ |
||
199 | View Code Duplication | private function isHexidecimalNumericString($tokens, $stackPtr) { |
|
208 | |||
209 | }//end class |
||
210 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.