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 |
||
14 | class MetaBox extends Component |
||
15 | { |
||
16 | use Condition; |
||
17 | use Instruction; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | public $metaboxes = []; |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc} |
||
26 | */ |
||
27 | public function init() |
||
34 | |||
35 | /** |
||
36 | * @return array |
||
37 | * @filter rwmb_meta_boxes |
||
38 | */ |
||
39 | public function register() |
||
49 | |||
50 | /** |
||
51 | * @return bool |
||
52 | * @filter rwmb_show |
||
53 | */ |
||
54 | public function show( $bool, array $metabox ) |
||
63 | |||
64 | /** |
||
65 | * @return int |
||
66 | */ |
||
67 | protected function getPostId() |
||
74 | |||
75 | /** |
||
76 | * @return array |
||
77 | */ |
||
78 | protected function getPostTypes() |
||
87 | |||
88 | /** |
||
89 | * @return string|array |
||
90 | */ |
||
91 | protected function getValue( $key, $group ) |
||
97 | |||
98 | /** |
||
99 | * @return bool |
||
100 | */ |
||
101 | protected function hasPostType( array $metabox ) |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | View Code Duplication | protected function normalize() |
|
127 | |||
128 | /** |
||
129 | * @param string $depends |
||
130 | * @param string $parentId |
||
131 | * @return string |
||
132 | */ |
||
133 | protected function normalizeDepends( $depends, array $data, $parentId ) |
||
139 | |||
140 | /** |
||
141 | * @return array |
||
142 | */ |
||
143 | protected function normalizeFields( array $fields, array $data, $parentId ) |
||
158 | |||
159 | /** |
||
160 | * @param string $id |
||
161 | * @param string $parentId |
||
162 | * @return string |
||
163 | */ |
||
164 | protected function normalizeId( $id, array $data, $parentId ) |
||
168 | |||
169 | /** |
||
170 | * @param mixed $types |
||
171 | * @return array |
||
172 | */ |
||
173 | protected function normalizePostTypes( $types ) |
||
177 | |||
178 | /** |
||
179 | * @return array |
||
180 | */ |
||
181 | protected function setDependencies( array $metabox ) |
||
195 | } |
||
196 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.