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 |
||
20 | final class OperatorToken extends AbstractToken |
||
21 | { |
||
22 | /** |
||
23 | * |
||
24 | * @var array |
||
25 | */ |
||
26 | protected static $operators = array('*', '/', '+', '-', '^'); |
||
27 | |||
28 | /** |
||
29 | * |
||
30 | * @param type $assoc |
||
31 | * @return integer |
||
32 | */ |
||
33 | 7 | public function getPriority($assoc = 'left') |
|
65 | |||
66 | /** |
||
67 | * |
||
68 | * @return boolean |
||
69 | */ |
||
70 | 7 | public function isLeftAssoc() |
|
74 | |||
75 | /** |
||
76 | * |
||
77 | * @return boolean |
||
78 | */ |
||
79 | 7 | public function isRightAssoc() |
|
83 | |||
84 | /** |
||
85 | * |
||
86 | * @return array |
||
87 | */ |
||
88 | 28 | public static function getAllowedOperators() |
|
92 | |||
93 | /** |
||
94 | * |
||
95 | * @param string $value |
||
96 | * @return string |
||
97 | */ |
||
98 | 21 | protected function sanitize($value) |
|
102 | |||
103 | /** |
||
104 | * |
||
105 | * @param string $value |
||
106 | * @return boolean |
||
107 | */ |
||
108 | 28 | protected function validate($value) |
|
112 | } |
||
113 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.