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 |
||
30 | View Code Duplication | abstract class AbstractDeleteTemplateRequest extends AbstractBaseRequest |
|
|
|||
31 | { |
||
32 | |||
33 | const REQUEST_ACTION = '_template'; |
||
34 | |||
35 | /** |
||
36 | * @param string $templateName |
||
37 | * @param SerializerInterface $serializer |
||
38 | * @param array $serializerParams |
||
39 | */ |
||
40 | 33 | public function __construct($templateName, SerializerInterface $serializer, array $serializerParams = array()) |
|
41 | { |
||
42 | 33 | $this->serializer = $serializer; |
|
43 | 33 | $this->serializerParams = $serializerParams; |
|
44 | |||
45 | 33 | if (!empty($templateName)) { |
|
46 | 33 | $this->type = $templateName; |
|
47 | 33 | } |
|
48 | 33 | } |
|
49 | |||
50 | /** |
||
51 | * @inheritdoc |
||
52 | */ |
||
53 | 3 | public function getMethod() |
|
57 | |||
58 | /** |
||
59 | * @inheritdoc |
||
60 | */ |
||
61 | 3 | public function getIndex() |
|
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | 3 | public function getAction() |
|
73 | |||
74 | /** |
||
75 | * @inheritdoc |
||
76 | */ |
||
77 | 3 | public function getBody() |
|
81 | |||
82 | /** |
||
83 | * @inheritdoc |
||
84 | */ |
||
85 | 3 | public function setBody($body) |
|
89 | |||
90 | /** |
||
91 | * Sets the template name |
||
92 | * |
||
93 | * @param $name |
||
94 | * |
||
95 | * @author Daniel Wendlandt |
||
96 | */ |
||
97 | 3 | public function setTemplateName($name) |
|
101 | } |
||
102 |
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.