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 |
||
20 | View Code Duplication | class SerializerContext implements DynamoAnnotation |
|
1 ignored issue
–
show
|
|||
21 | { |
||
22 | const NAME = 'serializer_context'; |
||
23 | |||
24 | /** |
||
25 | * @var array |
||
26 | */ |
||
27 | private $values; |
||
28 | |||
29 | /** |
||
30 | * Constructor |
||
31 | * |
||
32 | * @param array $params |
||
33 | */ |
||
34 | public function __construct(array $params) |
||
41 | |||
42 | /** |
||
43 | * @return array |
||
44 | */ |
||
45 | public function getContext() |
||
49 | |||
50 | /** |
||
51 | * The name of the annotation or class of annotations |
||
52 | * |
||
53 | * @return string |
||
54 | */ |
||
55 | public function getName() |
||
59 | |||
60 | /** |
||
61 | * Whether or not multiple annotations of this type can |
||
62 | * be added to a method |
||
63 | * |
||
64 | * @return bool |
||
65 | */ |
||
66 | public function allowMultiple() |
||
70 | } |
||
71 |
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.