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 |
||
| 37 | class FormHelper extends CakeFormHelper |
||
| 38 | { |
||
| 39 | |||
| 40 | use HelperTrait; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * List of helpers used by this helper. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | public $helpers = [ |
||
| 48 | 'Url' => ['className' => 'Core.Url'], |
||
| 49 | 'Html' => ['className' => 'Core.Html'], |
||
| 50 | ]; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Hold js form type. |
||
| 54 | * |
||
| 55 | * @var bool |
||
| 56 | */ |
||
| 57 | protected $_isJsForm = false; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * HtmlHelper constructor. |
||
| 61 | * |
||
| 62 | * @param View $View |
||
| 63 | * @param array $config |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function __construct(View $View, array $config = []) |
|
| 72 | |||
| 73 | /** |
||
| 74 | * Creates a `<button>` tag. |
||
| 75 | * |
||
| 76 | * @param string $title |
||
| 77 | * @param array $options |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function button($title, array $options = []) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Create html form. |
||
| 92 | * |
||
| 93 | * @param mixed $model |
||
| 94 | * @param array $options |
||
| 95 | * @return string |
||
| 96 | */ |
||
| 97 | public function create($model = null, array $options = []) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * End html form. |
||
| 131 | * |
||
| 132 | * @param array $secureAttributes |
||
| 133 | * @return string |
||
| 134 | */ |
||
| 135 | public function end(array $secureAttributes = []) |
||
| 146 | |||
| 147 | /** |
||
| 148 | * Add the default suite of context providers provided. |
||
| 149 | * |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | protected function _addDefaultContextProviders() |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Add the entity suite of context providers provided. |
||
| 171 | * |
||
| 172 | * @param $request |
||
| 173 | * @param $data |
||
| 174 | * @return EntityContext |
||
| 175 | */ |
||
| 176 | protected function _addEntityContent($request, $data) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Add the form suite of context providers provided. |
||
| 189 | * |
||
| 190 | * @return void |
||
| 191 | */ |
||
| 192 | protected function _addFormContextProvider() |
||
| 200 | |||
| 201 | /** |
||
| 202 | * Add the array suite of context providers provided. |
||
| 203 | * |
||
| 204 | * @return void |
||
| 205 | */ |
||
| 206 | protected function _addFormArrayProvider() |
||
| 214 | } |
||
| 215 |
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.