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 |
||
| 29 | class FormHelper extends CakeFormHelper |
||
| 30 | { |
||
| 31 | |||
| 32 | use HelperTrait; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * List of helpers used by this helper. |
||
| 36 | * |
||
| 37 | * @var array |
||
| 38 | */ |
||
| 39 | public $helpers = [ |
||
| 40 | 'Url' => ['className' => 'Core.Url'], |
||
| 41 | 'Html' => ['className' => 'Core.Html'], |
||
| 42 | ]; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Hold js form type. |
||
| 46 | * |
||
| 47 | * @var bool |
||
| 48 | */ |
||
| 49 | protected $_isJsForm = false; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * HtmlHelper constructor. |
||
| 53 | * |
||
| 54 | * @param View $View |
||
| 55 | * @param array $config |
||
| 56 | */ |
||
| 57 | View Code Duplication | public function __construct(View $View, array $config = []) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Create html form. |
||
| 67 | * |
||
| 68 | * @param mixed $model |
||
| 69 | * @param array $options |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | public function create($model = null, array $options = []) |
||
| 103 | |||
| 104 | /** |
||
| 105 | * End html form. |
||
| 106 | * |
||
| 107 | * @param array $secureAttributes |
||
| 108 | * @return string |
||
| 109 | */ |
||
| 110 | public function end(array $secureAttributes = []) |
||
| 121 | } |
||
| 122 |
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.