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 | class Type implements TypeInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var int|string |
||
22 | */ |
||
23 | protected $id; |
||
24 | |||
25 | /** |
||
26 | * @var string |
||
27 | */ |
||
28 | protected $name; |
||
29 | |||
30 | 10 | public function __construct($id, $name = null) |
|
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | 6 | public function getId() |
|
40 | { |
||
41 | 6 | return $this->id; |
|
42 | } |
||
43 | |||
44 | /** |
||
45 | * {@inheritdoc} |
||
46 | */ |
||
47 | 10 | public function getName() |
|
51 | |||
52 | 2 | public function getUniqueId() |
|
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | 2 | public function equals(TypeInterface $other) |
|
65 | |||
66 | 6 | public function matches(TypeInterface $other) |
|
72 | |||
73 | 6 | View Code Duplication | protected function checkMatches($lhs, $rhs) |
81 | |||
82 | public function jsonSerialize() |
||
89 | } |
||
90 |