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 |
||
5 | View Code Duplication | final class VotingDecisionEnum |
|
|
|||
6 | { |
||
7 | /** |
||
8 | * @var string |
||
9 | */ |
||
10 | private $value; |
||
11 | |||
12 | /** |
||
13 | * @var self[] |
||
14 | */ |
||
15 | static private $registry = []; |
||
16 | |||
17 | private function __construct($value) |
||
21 | |||
22 | |||
23 | /** |
||
24 | * @return self |
||
25 | */ |
||
26 | public static function ALLOWED() |
||
30 | |||
31 | |||
32 | /** |
||
33 | * @return self |
||
34 | */ |
||
35 | public static function DENIED() |
||
39 | |||
40 | |||
41 | /** |
||
42 | * @param $string |
||
43 | * @return self |
||
44 | */ |
||
45 | private static function instance($string) |
||
52 | |||
53 | |||
54 | /** |
||
55 | * @return string |
||
56 | */ |
||
57 | public function __toString() |
||
61 | } |
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.