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 |
||
10 | View Code Duplication | class AttributesObject implements ObjectInterface { |
|
11 | use AtMemberManager; |
||
12 | |||
13 | /** @var array */ |
||
14 | protected $attributes = []; |
||
15 | |||
16 | /** |
||
17 | * human api |
||
18 | */ |
||
19 | |||
20 | /** |
||
21 | * @note if an `id` is set inside $attributes, it is removed from there |
||
22 | * it is common to find it inside, and not doing so will cause an exception |
||
23 | * |
||
24 | * @param array $attributes |
||
25 | * @return AttributesObject |
||
26 | */ |
||
27 | public static function fromArray(array $attributes) { |
||
38 | |||
39 | /** |
||
40 | * @param object $attributes |
||
41 | * @return AttributesObject |
||
42 | */ |
||
43 | public static function fromObject($attributes) { |
||
48 | |||
49 | /** |
||
50 | * spec api |
||
51 | */ |
||
52 | |||
53 | /** |
||
54 | * @param string $key |
||
55 | * @param mixed $value |
||
56 | */ |
||
57 | public function add($key, $value) { |
||
66 | |||
67 | /** |
||
68 | * internal api |
||
69 | */ |
||
70 | |||
71 | /** |
||
72 | * @internal |
||
73 | * |
||
74 | * @return string[] |
||
75 | */ |
||
76 | public function getKeys() { |
||
79 | |||
80 | /** |
||
81 | * ObjectInterface |
||
82 | */ |
||
83 | |||
84 | /** |
||
85 | * @inheritDoc |
||
86 | */ |
||
87 | public function isEmpty() { |
||
90 | |||
91 | /** |
||
92 | * @inheritDoc |
||
93 | */ |
||
94 | public function toArray() { |
||
97 | } |
||
98 |