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 |
||
8 | abstract class AbstractStyle |
||
9 | { |
||
10 | protected $byValueOperator = 'OR'; |
||
11 | |||
12 | /** |
||
13 | * @var array |
||
14 | */ |
||
15 | private $byValues = []; |
||
16 | |||
17 | /** |
||
18 | * Display the values with AND or OR (if multiple showOnValues are defined). |
||
19 | * |
||
20 | * @param string $operator |
||
21 | */ |
||
22 | View Code Duplication | public function setByValueOperator($operator = 'OR') |
|
30 | |||
31 | /** |
||
32 | * Get the show on value operator, e.g. |
||
33 | * OR, AND. |
||
34 | * |
||
35 | * @return string |
||
36 | */ |
||
37 | public function getByValueOperator() |
||
41 | |||
42 | /** |
||
43 | * Set the style value based and not general. |
||
44 | * |
||
45 | * @param AbstractColumn $column |
||
46 | * @param mixed $value |
||
47 | * @param string $operator |
||
48 | */ |
||
49 | public function addByValue(AbstractColumn $column, $value, $operator = Filter::EQUAL) |
||
57 | |||
58 | /** |
||
59 | * @return array |
||
60 | */ |
||
61 | public function getByValues() |
||
65 | |||
66 | /** |
||
67 | * @return bool |
||
68 | */ |
||
69 | public function hasByValues() |
||
77 | |||
78 | /** |
||
79 | * @param array $row |
||
80 | * |
||
81 | * @return bool |
||
82 | */ |
||
83 | View Code Duplication | public function isApply(array $row) |
|
119 | } |
||
120 |
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.