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 | class ProtectPanReply implements IProtectPanReply |
|
|
|||
31 | { |
||
32 | use TTopLevelPayload; |
||
33 | |||
34 | /** @var string */ |
||
35 | protected $token; |
||
36 | |||
37 | /** |
||
38 | * @param IValidatorIterator |
||
39 | * @param ISchemaValidator |
||
40 | * @param IPayloadMap |
||
41 | * @param LoggerInterface |
||
42 | * @param IPayload |
||
43 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
44 | */ |
||
45 | public function __construct( |
||
61 | |||
62 | public function getToken() |
||
66 | |||
67 | /** |
||
68 | * Serialize the various parts of the payload into XML strings and |
||
69 | * simply concatenate them together. |
||
70 | * @return string |
||
71 | */ |
||
72 | protected function serializeContents() |
||
76 | |||
77 | protected function getSchemaFile() |
||
81 | |||
82 | /** |
||
83 | * Return the name of the xml root node. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | protected function getRootNodeName() |
||
91 | |||
92 | /** |
||
93 | * The XML namespace for the payload. |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | protected function getXmlNamespace() |
||
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.