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 |
||
18 | abstract class XmlApiPageBase extends ApiPageBase implements IXmlApiAction |
||
19 | { |
||
20 | /** |
||
21 | * API result document |
||
22 | * @var DOMDocument |
||
23 | */ |
||
24 | protected $document; |
||
25 | |||
26 | public function __construct() |
||
30 | |||
31 | /** |
||
32 | * Main function for this page, when no specific actions are called. |
||
33 | * |
||
34 | * @throws ApiException |
||
35 | * @return void |
||
36 | */ |
||
37 | View Code Duplication | final protected function main() |
|
62 | |||
63 | /** |
||
64 | * Method that runs API action |
||
65 | * |
||
66 | * @param DOMElement $apiDocument |
||
67 | * |
||
68 | * @return DOMElement |
||
69 | */ |
||
70 | abstract public function executeApiAction(DOMElement $apiDocument); |
||
71 | |||
72 | /** |
||
73 | * @return string |
||
74 | */ |
||
75 | final public function runApiPage() |
||
92 | } |
||
93 |
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.