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 |
||
31 | View Code Duplication | abstract class AbstractDeleteWarmerRequest extends AbstractBaseRequest |
|
|
|||
32 | { |
||
33 | |||
34 | const REQUEST_ACTION = '_warmer'; |
||
35 | |||
36 | /** |
||
37 | * @var null|string |
||
38 | */ |
||
39 | private $warmerName = null; |
||
40 | |||
41 | /** |
||
42 | * @inheritdoc |
||
43 | */ |
||
44 | 3 | public function getMethod() |
|
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | 6 | public function getAction() |
|
53 | { |
||
54 | 6 | if (empty($this->warmerName)) { |
|
55 | 3 | throw new RequestException('Warmer name is not set'); |
|
56 | } |
||
57 | |||
58 | 3 | return self::REQUEST_ACTION . '/' . $this->warmerName; |
|
59 | } |
||
60 | |||
61 | /** |
||
62 | * Gets the name of the warmer |
||
63 | * |
||
64 | * @return null|string |
||
65 | * @author Daniel Wendlandt |
||
66 | */ |
||
67 | 3 | public function getWarmerName() |
|
71 | |||
72 | /** |
||
73 | * sets the name of the warmer |
||
74 | * |
||
75 | * @param string $warmerName |
||
76 | * |
||
77 | * @author Daniel Wendlandt |
||
78 | */ |
||
79 | 6 | public function setWarmerName($warmerName) |
|
83 | |||
84 | /** |
||
85 | * @inheritdoc |
||
86 | */ |
||
87 | 3 | public function getBody() |
|
91 | |||
92 | /** |
||
93 | * @inheritdoc |
||
94 | */ |
||
95 | 3 | public function setBody($body) |
|
99 | |||
100 | } |
||
101 |
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.