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 |
||
12 | abstract class AbstractSmartIdQuery implements QueryInterface |
||
13 | { |
||
14 | /** @var string user personal code */ |
||
15 | private $code; |
||
16 | |||
17 | /** @var string Country related to personal code. Example EE */ |
||
18 | private $country; |
||
19 | |||
20 | /** |
||
21 | * @param string $code |
||
22 | * @param string $country |
||
23 | */ |
||
24 | 5 | public function __construct( |
|
31 | |||
32 | /** |
||
33 | * Field and values association used in query |
||
34 | * @return array |
||
35 | */ |
||
36 | 1 | public function getFields() |
|
45 | |||
46 | /** |
||
47 | * Validation constraints for request data validation |
||
48 | * @return Assert\Collection |
||
49 | */ |
||
50 | 1 | View Code Duplication | public function getValidationConstraints() |
62 | |||
63 | /** |
||
64 | * HTTP method to use |
||
65 | * @return string |
||
66 | */ |
||
67 | 1 | public function getMethod() |
|
71 | } |
||
72 |
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.