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 |
||
15 | abstract class JsonApiPageBase extends ApiPageBase implements IJsonApiAction |
||
16 | { |
||
17 | /** |
||
18 | * Main function for this page, when no specific actions are called. |
||
19 | * |
||
20 | * @return void |
||
21 | * @throws ApiException |
||
22 | */ |
||
23 | View Code Duplication | final protected function main() |
|
48 | |||
49 | /** |
||
50 | * Method that runs API action |
||
51 | * |
||
52 | * @return object|array The modified API document |
||
53 | */ |
||
54 | public abstract function executeApiAction(); |
||
55 | |||
56 | /** |
||
57 | * @return string |
||
58 | */ |
||
59 | final public function runApiPage() |
||
80 | } |
||
81 |
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.