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 |
||
9 | class LinkObject implements ObjectInterface { |
||
|
|||
10 | use AtMemberManager; |
||
11 | |||
12 | /** @var string */ |
||
13 | protected $href; |
||
14 | /** @var MetaObject */ |
||
15 | protected $meta; |
||
16 | |||
17 | /** |
||
18 | * @param string $href |
||
19 | * @param array $meta optional |
||
20 | */ |
||
21 | public function __construct($href=null, array $meta=[]) { |
||
29 | |||
30 | /** |
||
31 | * human api |
||
32 | */ |
||
33 | |||
34 | /** |
||
35 | * @param string $key |
||
36 | * @param mixed $value |
||
37 | */ |
||
38 | public function addMeta($key, $value) { |
||
45 | |||
46 | /** |
||
47 | * spec api |
||
48 | */ |
||
49 | |||
50 | /** |
||
51 | * @param string $href |
||
52 | */ |
||
53 | public function setHref($href) { |
||
56 | |||
57 | /** |
||
58 | * @param MetaObject $metaObject |
||
59 | */ |
||
60 | public function setMetaObject(MetaObject $metaObject) { |
||
63 | |||
64 | /** |
||
65 | * ObjectInterface |
||
66 | */ |
||
67 | |||
68 | /** |
||
69 | * @inheritDoc |
||
70 | */ |
||
71 | View Code Duplication | public function isEmpty() { |
|
84 | |||
85 | /** |
||
86 | * @inheritDoc |
||
87 | */ |
||
88 | View Code Duplication | public function toArray() { |
|
99 | } |
||
100 |