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 |
||
| 8 | trait StartupConfigTrait { |
||
| 9 | protected static $config; |
||
| 10 | protected static $ctrlNS; |
||
| 11 | |||
| 12 | public static function getConfig() { |
||
| 15 | |||
| 16 | public static function setConfig($config) { |
||
| 19 | |||
| 20 | public static function getModelsDir() { |
||
| 23 | |||
| 24 | public static function getModelsCompletePath() { |
||
| 27 | |||
| 28 | View Code Duplication | protected static function needsKeyInConfigArray(&$result, $array, $needs) { |
|
| 35 | |||
| 36 | View Code Duplication | public static function getNS($part = "controllers") { |
|
| 44 | |||
| 45 | protected static function setCtrlNS() { |
||
| 48 | |||
| 49 | View Code Duplication | public static function checkDbConfig() { |
|
| 60 | |||
| 61 | View Code Duplication | public static function checkModelsConfig() { |
|
| 71 | |||
| 72 | |||
| 73 | View Code Duplication | public static function reloadConfig(){ |
|
| 80 | |||
| 81 | View Code Duplication | public static function saveConfig($content){ |
|
| 90 | } |
||
| 91 | |||
| 92 |
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.