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 |
||
| 21 | { |
||
| 22 | |||
| 23 | public function getConsoleUsage(Console $console) |
||
| 24 | { |
||
| 25 | return array( |
||
| 26 | 'Manipulation of jobs database', |
||
| 27 | 'jobs generatekeywords [--filter=]' => '(Re-)Generates keywords for all jobs.', |
||
| 28 | array('--filter=JSON', "available keys:\n" |
||
| 29 | . "- 'before:ISODate' -> only jobs before the given date\n" |
||
| 30 | . "- 'after':ISODate' -> only jobs after the given date\n" |
||
| 31 | . "- 'title':String -> exakt title to match or if starting with '/' -> MongoRegex\n" |
||
| 32 | . "- 'limit':INT -> Limit result."), |
||
| 33 | ); |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Loads module specific configuration. |
||
| 38 | * |
||
| 39 | * @return array |
||
| 40 | */ |
||
| 41 | public function getConfig() |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Loads module specific autoloader configuration. |
||
| 48 | * |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | View Code Duplication | public function getAutoloaderConfig() |
|
| 62 | |||
| 63 | View Code Duplication | public function onBootstrap(MvcEvent $e) |
|
| 72 | } |
||
| 73 |
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.