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 |
||
15 | class Action extends AbstractColumn implements ActionAwareInterface |
||
16 | { |
||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $actions = []; |
||
21 | |||
22 | /** |
||
23 | * @var Url |
||
24 | */ |
||
25 | protected $urlHelper; |
||
26 | |||
27 | |||
28 | View Code Duplication | public function __construct(array $options = []) |
|
45 | |||
46 | /** |
||
47 | * Возвращает набор действий в колонке |
||
48 | * @return array|ActionInterface[] |
||
49 | */ |
||
50 | public function getActions() |
||
54 | |||
55 | /** |
||
56 | * Устанавливает набор действий в колонку |
||
57 | * @param array $actions |
||
58 | * @return $this |
||
59 | */ |
||
60 | public function setActions($actions) |
||
65 | |||
66 | /** |
||
67 | * Добавляет действие в колонку |
||
68 | * @param ActionInterface|array $action |
||
69 | * @return $this |
||
70 | */ |
||
71 | public function addAction($action) |
||
81 | |||
82 | /** |
||
83 | * @return Url |
||
84 | */ |
||
85 | public function getUrlHelper() |
||
89 | |||
90 | /** |
||
91 | * @param Url $urlHelper |
||
92 | * @return $this |
||
93 | */ |
||
94 | public function setUrlHelper($urlHelper) |
||
99 | } |
||
100 |
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.