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 |
||
11 | class Tariff implements SerializableInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var MultilingualString |
||
15 | */ |
||
16 | private $name; |
||
17 | |||
18 | /** |
||
19 | * @var Price |
||
20 | */ |
||
21 | private $price; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | private $currencyCodeString; |
||
27 | |||
28 | /** |
||
29 | * @param MultilingualString $name |
||
30 | * @param Price $price |
||
31 | * @param Currency $currency |
||
32 | */ |
||
33 | public function __construct( |
||
42 | |||
43 | /** |
||
44 | * @return MultilingualString |
||
45 | */ |
||
46 | public function getName() |
||
50 | |||
51 | /** |
||
52 | * @return Price |
||
53 | */ |
||
54 | public function getPrice() |
||
58 | |||
59 | /** |
||
60 | * @return Currency |
||
61 | */ |
||
62 | public function getCurrency() |
||
66 | |||
67 | /** |
||
68 | * @return array |
||
69 | */ |
||
70 | public function serialize() |
||
78 | |||
79 | /** |
||
80 | * @param array $data |
||
81 | * @return Tariff |
||
82 | */ |
||
83 | public static function deserialize(array $data) |
||
91 | |||
92 | /** |
||
93 | * @param Udb3ModelTariff $udb3ModelTariff |
||
94 | * @return Tariff |
||
95 | */ |
||
96 | View Code Duplication | public static function fromUdb3ModelTariff(Udb3ModelTariff $udb3ModelTariff) |
|
104 | } |
||
105 |
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.