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 | abstract class PHPCompatibility_AbstractNewFeatureSniff |
||
|
|||
18 | extends PHPCompatibility_AbstractComplexVersionSniff |
||
19 | { |
||
20 | |||
21 | |||
22 | /** |
||
23 | * Determine whether an error/warning should be thrown for an item based on collected information. |
||
24 | * |
||
25 | * @param array $errorInfo Detail information about an item. |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | protected function shouldThrowError(array $errorInfo) |
||
33 | |||
34 | |||
35 | /** |
||
36 | * Retrieve the relevant detail (version) information for use in an error message. |
||
37 | * |
||
38 | * @param array $itemArray Version and other information about the item. |
||
39 | * @param array $itemInfo Base information about the item. |
||
40 | * |
||
41 | * @return array |
||
42 | */ |
||
43 | public function getErrorInfo(array $itemArray, array $itemInfo) |
||
64 | |||
65 | |||
66 | /** |
||
67 | * Get the error message template for this sniff. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | protected function getErrorMsgTemplate() |
||
75 | |||
76 | |||
77 | /** |
||
78 | * Generates the error or warning for this item. |
||
79 | * |
||
80 | * @param PHP_CodeSniffer_File $phpcsFile The file being scanned. |
||
81 | * @param int $stackPtr The position of the relevant token in |
||
82 | * the stack. |
||
83 | * @param array $itemInfo Base information about the item. |
||
84 | * @param array $errorInfo Array with detail (version) information |
||
85 | * relevant to the item. |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | public function addError(PHP_CodeSniffer_File $phpcsFile, $stackPtr, array $itemInfo, array $errorInfo) |
||
105 | |||
106 | |||
107 | }//end class |
||
108 |
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.