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 |
||
18 | abstract class AbstractTarget implements TargetInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var int|string |
||
22 | */ |
||
23 | protected $id; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $type; |
||
29 | |||
30 | 10 | public function __construct($id, $type) |
|
35 | |||
36 | /** |
||
37 | * @return int |
||
38 | */ |
||
39 | 8 | public function getId() |
|
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 8 | public function getType() |
|
51 | |||
52 | /** |
||
53 | * @return string |
||
54 | */ |
||
55 | 5 | public function getUniqueId() |
|
62 | |||
63 | /** |
||
64 | * @return bool |
||
65 | */ |
||
66 | 2 | public function equals(TargetInterface $other): bool |
|
70 | |||
71 | /** |
||
72 | * @return bool |
||
73 | */ |
||
74 | 6 | public function matches(TargetInterface $other): bool |
|
78 | |||
79 | 6 | public function checkMatches(TargetInterface $other): bool |
|
95 | |||
96 | 6 | protected function matchIds(TargetInterface $other) |
|
100 | |||
101 | 6 | protected function matchTypes(TargetInterface $other) |
|
105 | |||
106 | 6 | View Code Duplication | protected function matchStrings($lhs, $rhs) |
114 | |||
115 | |||
116 | public function jsonSerialize() |
||
120 | } |
||
121 |