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 |
||
27 | abstract class AbstractRange extends AbstractSingleRequestValueFilter implements |
||
28 | FieldAwareInterface, |
||
29 | ViewDataFactoryInterface |
||
30 | { |
||
31 | use FieldAwareTrait; |
||
32 | |||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | private $inclusive = false; |
||
37 | |||
38 | /** |
||
39 | * @param bool $inclusive |
||
40 | * |
||
41 | * @return $this |
||
42 | */ |
||
43 | public function setInclusive($inclusive) |
||
44 | { |
||
45 | $this->inclusive = $inclusive; |
||
46 | |||
47 | return $this; |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @return bool |
||
52 | */ |
||
53 | public function isInclusive() |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function createViewData() |
||
65 | |||
66 | /** |
||
67 | * {@inheritdoc} |
||
68 | */ |
||
69 | View Code Duplication | public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
|
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function isRelated() |
||
84 | } |
||
85 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.