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 |
||
19 | class DBResultRow extends DBResult{ |
||
20 | |||
21 | /** |
||
22 | * @param string $name |
||
23 | * @param array $arguments |
||
24 | * |
||
25 | * @return mixed|null |
||
26 | */ |
||
27 | public function __call(string $name, array $arguments){ |
||
40 | |||
41 | /** |
||
42 | * @param string $name |
||
43 | * |
||
44 | * @return mixed|null |
||
45 | */ |
||
46 | public function __get(string $name) { |
||
54 | |||
55 | /** |
||
56 | * @link http://api.prototypejs.org/language/Enumerable/prototype/pluck/ |
||
57 | * |
||
58 | * @param string $property |
||
59 | * |
||
60 | * @return array |
||
61 | */ |
||
62 | public function pluck(string $property):array { |
||
65 | |||
66 | /** |
||
67 | * @param int $offset |
||
68 | * @param array $value |
||
69 | * |
||
70 | * @return void |
||
71 | */ |
||
72 | View Code Duplication | public function offsetSet($offset, $value){ |
|
82 | |||
83 | } |
||
84 |
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.