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 |
||
32 | View Code Duplication | class ReferenceDetails |
|
|
|||
33 | { |
||
34 | const REFERENCE_TYPE_PAX = 'P'; |
||
35 | |||
36 | const REFERENCE_TYPE_ADULT_PASSENGER = "PA"; |
||
37 | |||
38 | const REFERENCE_TYPE_INFANT_PASSENGER = "PI"; |
||
39 | |||
40 | const REFERENCE_TYPE_SEGMENT = 'S'; |
||
41 | |||
42 | /** |
||
43 | * self::TYPE_* |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | public $type; |
||
48 | |||
49 | /** |
||
50 | * @var int|string |
||
51 | */ |
||
52 | public $value; |
||
53 | |||
54 | /** |
||
55 | * ReferenceDetails constructor. |
||
56 | * |
||
57 | * @param string $type |
||
58 | * @param int|string $value |
||
59 | */ |
||
60 | public function __construct($type, $value) |
||
65 | } |
||
66 |
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.