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 |
||
21 | abstract class PriceCest |
||
22 | { |
||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $id; |
||
27 | |||
28 | /** |
||
29 | * @param Manager $I |
||
30 | * @return array of settings for future plan |
||
31 | * ```php |
||
32 | * [ |
||
33 | * 'type' => 'Server', // Type of the future plan |
||
34 | * 'templateName' => 'Main template', |
||
35 | * 'priceTypes' => ['Main prices', 'Parts prices'], |
||
36 | * 'object' => 'DS5000', |
||
37 | * ], |
||
38 | * ``` |
||
39 | */ |
||
40 | abstract protected function suggestedPricesOptionsProvider(Manager $I): array; |
||
41 | |||
42 | /** |
||
43 | * @param Manager $I |
||
44 | */ |
||
45 | public function ensureICanCreateSuggestedPrices(Manager $I): void |
||
63 | |||
64 | /** |
||
65 | * @param Manager $I |
||
66 | * @param string $name |
||
67 | * @param string $type |
||
68 | * @return int created plan ID |
||
69 | */ |
||
70 | protected function createPlan(Manager $I, string $name, string $type): int |
||
84 | |||
85 | View Code Duplication | public function ensureICanUpdatePrices(Manager $I, Scenario $scenario): void |
|
94 | |||
95 | View Code Duplication | public function ensureICanDeletePrices(Manager $I, Scenario $scenario): void |
|
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.