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 |
||
| 20 | class Module implements ConsoleUsageProviderInterface, AutoloaderProviderInterface |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * Displays console options |
||
| 24 | * |
||
| 25 | * @param Console $console |
||
| 26 | * @return array|null|string |
||
| 27 | */ |
||
| 28 | public function getConsoleUsage(Console $console) |
||
| 29 | { |
||
| 30 | return array( |
||
| 31 | 'Manipulation of applications collection', |
||
| 32 | 'applications generatekeywords' => '(Re-)Generates keywords for all applications.', |
||
| 33 | 'applications calculate-rating' => '(Re-)Calculates average rating for all applications.', |
||
| 34 | 'applications cleanup' => 'removes applications drafts.', |
||
| 35 | 'applications list' => 'list view scripts.', |
||
| 36 | 'applications reset-files-permissions [--filter=]' => 'Resets (means: Set again) the permissions of attachments and contact images', |
||
| 37 | array('--filter=JSON', "available keys:\n" |
||
| 38 | . "- before ISODate only applications before the given date\n" |
||
| 39 | . "- after ISODate only applications after the given date\n" |
||
| 40 | . "- id String Mongo ID of the application\n" |
||
| 41 | . "- isDraft Boolean "), |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Loads module specific configuration. |
||
| 47 | * |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | public function getConfig() |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Loads module specific autoloader configuration. |
||
| 57 | * |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | View Code Duplication | public function getAutoloaderConfig() |
|
| 71 | } |
||
| 72 |
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.