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 |
||
| 27 | class AssetsHelper extends AppHelper |
||
| 28 | { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Use helpers. |
||
| 32 | * |
||
| 33 | * @var array |
||
| 34 | */ |
||
| 35 | public $helpers = [ |
||
| 36 | 'Url' => ['className' => 'Core.Url'], |
||
| 37 | 'Html' => ['className' => 'Core.Html'], |
||
| 38 | ]; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Default assets options. |
||
| 42 | * |
||
| 43 | * @var array |
||
| 44 | */ |
||
| 45 | protected $_options = [ |
||
| 46 | 'block' => true, |
||
| 47 | 'fullBase' => true, |
||
| 48 | ]; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Include bootstrap. |
||
| 52 | * |
||
| 53 | * @return $this |
||
| 54 | */ |
||
| 55 | View Code Duplication | public function bootstrap() |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Include fancybox. |
||
| 65 | * |
||
| 66 | * @return $this |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function fancyBox() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Include font awesome. |
||
| 78 | * |
||
| 79 | * @return $this |
||
| 80 | */ |
||
| 81 | public function fontAwesome() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Include jquery lib. |
||
| 89 | * |
||
| 90 | * @return $this |
||
| 91 | */ |
||
| 92 | public function jquery() |
||
| 97 | |||
| 98 | /** |
||
| 99 | * Include jquery factory. |
||
| 100 | * |
||
| 101 | * @return $this |
||
| 102 | */ |
||
| 103 | public function jqueryFactory() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * Include materialize design. |
||
| 112 | * |
||
| 113 | * @return $this |
||
| 114 | */ |
||
| 115 | View Code Duplication | public function materialize() |
|
| 122 | |||
| 123 | /** |
||
| 124 | * Include sweet alert. |
||
| 125 | * |
||
| 126 | * @return $this |
||
| 127 | */ |
||
| 128 | View Code Duplication | public function sweetAlert() |
|
| 135 | |||
| 136 | /** |
||
| 137 | * Include ui kit framework. |
||
| 138 | * |
||
| 139 | * @return $this |
||
| 140 | */ |
||
| 141 | View Code Duplication | public function uikit() |
|
| 148 | |||
| 149 | /** |
||
| 150 | * Autoload plugin assets. |
||
| 151 | * |
||
| 152 | * @return void |
||
| 153 | */ |
||
| 154 | public function loadPluginAssets() |
||
| 171 | } |
||
| 172 |
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.