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 AbstractGetDocumentRequest extends AbstractBaseRequest |
|
|
|||
31 | { |
||
32 | /** |
||
33 | * @var null|string |
||
34 | */ |
||
35 | private $action = null; |
||
36 | |||
37 | /** |
||
38 | * @inheritdoc |
||
39 | */ |
||
40 | 3 | public function getMethod() |
|
41 | { |
||
42 | 3 | return RequestMethods::GET; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * @inheritdoc |
||
47 | */ |
||
48 | 6 | public function getAction() |
|
49 | { |
||
50 | 6 | if (null === $this->action) { |
|
51 | 3 | throw new RequestException('id can not be empty for this request'); |
|
52 | } |
||
53 | |||
54 | 3 | return $this->action; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | 3 | public function getBody() |
|
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | */ |
||
68 | 3 | public function setBody($body) |
|
72 | |||
73 | /** |
||
74 | * @inheritdoc |
||
75 | */ |
||
76 | 6 | public function setId($id) |
|
84 | } |
||
85 |
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.