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 |
||
5 | View Code Duplication | class OrSpecification extends Specification |
|
6 | { |
||
7 | /** |
||
8 | * @var Specification |
||
9 | */ |
||
10 | private $one; |
||
11 | |||
12 | /** |
||
13 | * @var Specification |
||
14 | */ |
||
15 | private $other; |
||
16 | |||
17 | /** |
||
18 | * @param Specification $one |
||
19 | * @param Specification $other |
||
20 | */ |
||
21 | 1 | public function __construct(Specification $one, Specification $other) |
|
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 1 | public function isSatisfiedBy($object): bool |
|
34 | } |
||
35 |