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 |
||
24 | View Code Duplication | class StringBinding extends AbstractBinding |
|
|
|||
25 | { |
||
26 | private $string; |
||
27 | |||
28 | 97 | public function __construct($string, $typeName, array $parameterValues = array()) |
|
34 | |||
35 | public function getString() |
||
39 | |||
40 | public function equals(Binding $other) |
||
41 | { |
||
42 | if (!parent::equals($other)) { |
||
43 | return false; |
||
44 | } |
||
45 | |||
46 | /* @var StringBinding $other */ |
||
47 | return $this->string === $other->string; |
||
48 | } |
||
49 | |||
50 | 69 | protected function preSerialize(array &$data) |
|
56 | |||
57 | 26 | protected function postUnserialize(array &$data) |
|
63 | } |
||
64 |
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.