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 |
||
8 | abstract class ValueObject |
||
9 | { |
||
10 | /** |
||
11 | * ValueObject constructor. |
||
12 | * |
||
13 | * @param array $properties |
||
14 | */ |
||
15 | public function __construct(array $properties = array()) |
||
21 | |||
22 | /** |
||
23 | * Disables magic set |
||
24 | * |
||
25 | * @param string $property |
||
26 | * @param mixed $value |
||
27 | * |
||
28 | * @throws PropertyNotFoundException |
||
29 | * @throws PropertyReadOnlyException |
||
30 | */ |
||
31 | View Code Duplication | public function __set($property, $value) |
|
38 | |||
39 | /** |
||
40 | * Magic get |
||
41 | * |
||
42 | * @param string $property |
||
43 | * |
||
44 | * @return mixed |
||
45 | * |
||
46 | * @throws PropertyNotFoundException |
||
47 | */ |
||
48 | View Code Duplication | public function __get($property) |
|
56 | } |
||
57 |
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.