| Conditions | 1 |
| Paths | 1 |
| Total Lines | 96 |
| Code Lines | 82 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 111 | public function createComponentVisitorForm(): Form |
||
| 112 | { |
||
| 113 | $provinces = $this->getProvinceModel()->all(); |
||
| 114 | |||
| 115 | $form = new Form; |
||
| 116 | |||
| 117 | $form->addText('name', 'Jméno:', 30) |
||
| 118 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 119 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
||
| 120 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 121 | $form->addText('surname', 'Příjmení:', 30) |
||
| 122 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 123 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
||
| 124 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 125 | $form->addText('nick', 'Přezdívka:', 30) |
||
| 126 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 127 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 20) |
||
| 128 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 129 | $form->addEmail('email', 'E-mail:') |
||
| 130 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 131 | ->setAttribute('size', 30) |
||
| 132 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 133 | $form->addTbDatePicker('birthday', 'Datum narození:', null, 16) |
||
| 134 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 135 | ->setFormat('d.m.Y') |
||
| 136 | ->setAttribute('placeholder', 'dd. mm. rrrr') |
||
| 137 | ->setAttribute('id', 'birthday') |
||
| 138 | ->setAttribute('class', 'datePicker') |
||
| 139 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 140 | $form->addText('street', 'Ulice:', 30) |
||
| 141 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 142 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 30) |
||
| 143 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 144 | $form->addText('city', 'Město:', 30) |
||
| 145 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 146 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 64) |
||
| 147 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 148 | $form->addText('postal_code', 'PSČ:', 30) |
||
| 149 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 150 | ->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnnnn!', '[1-9]{1}[0-9]{4}') |
||
| 151 | ->setAttribute('placeholder', '12345') |
||
| 152 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 153 | $form->addText('group_num', 'Číslo středika/přístavu:', 30) |
||
| 154 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 155 | ->addRule(Form::PATTERN, 'Číslo musí být ve formátu nnn.nn!', '[1-9]{1}[0-9a-zA-Z]{2}\.[0-9a-zA-Z]{1}[0-9a-zA-Z]{1}') |
||
| 156 | ->setAttribute('placeholder', '214.02') |
||
| 157 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 158 | $form->addText('group_name', 'Název střediska/přístavu:', 30) |
||
| 159 | ->setRequired(static::MESSAGE_REQUIRED) |
||
| 160 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50) |
||
| 161 | ->setAttribute('placeholder', '2. přístav Poutníci Kolín') |
||
| 162 | ->getLabelPrototype()->setAttribute('class', 'required'); |
||
| 163 | $form->addText('troop_name', 'Název oddílu:', 30) |
||
| 164 | ->setAttribute('placeholder', '22. oddíl Galeje') |
||
| 165 | ->addCondition(Form::FILLED, true) |
||
| 166 | ->addRule(Form::MAX_LENGTH, static::MESSAGE_MAX_LENGTH, 50); |
||
| 167 | |||
| 168 | $form->addSelect('province', 'Kraj:', $provinces) |
||
| 169 | ->setPrompt('zvolte kraj'); |
||
| 170 | |||
| 171 | $form = $this->buildMealSwitcher($form); |
||
| 172 | |||
| 173 | $form->addTextArea('arrival', 'Informace o příjezdu:', 50, 3) |
||
| 174 | ->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) přijedete na místo srazu.'); |
||
| 175 | $form->addTextArea('departure', 'Informace o odjezdu:', 50, 3) |
||
| 176 | ->setAttribute('placeholder', 'Napište, prosím, stručně jakým dopravním prostředkem a v kolik hodin (přibližně) sraz opustíte.'); |
||
| 177 | $form->addTextArea('comment', 'Dotazy, přání, připomínky, stížnosti:', 50, 8); |
||
| 178 | $form->addTextArea('question', 'Vaše nabídka:', 50, 8) |
||
| 179 | ->setAttribute('placeholder', 'Vaše nabídka na sdílení dobré praxe (co u vás umíte dobře a jste ochotni se o to podělit)'); |
||
| 180 | $form->addTextArea('question2', 'Počet a typy lodí:', 50, 8) |
||
| 181 | ->setAttribute('placeholder', 'Počet a typy lodí, které sebou přivezete (vyplňte pokud ano)'); |
||
| 182 | $form->addText('bill', 'Zaplaceno:', 30) |
||
| 183 | ->setDefaultValue(0); |
||
| 184 | $form->addText('cost', 'Poplatek:', 30) |
||
| 185 | ->setDefaultValue($this->getMeetingModel()->getPrice('cost')); |
||
| 186 | |||
| 187 | $form = $this->buildProgramSwitcher($form); |
||
| 188 | |||
| 189 | $form->addHidden('mid', $this->getMeetingId()); |
||
| 190 | $form->addHidden('meeting', $this->getMeetingId()); |
||
| 191 | $form->addHidden('backlink'); |
||
| 192 | |||
| 193 | $form->addSubmit('save', 'Uložit') |
||
| 194 | ->setAttribute('class', 'btn-primary') |
||
| 195 | ->onClick[] = [$this, 'processSave']; |
||
| 196 | $form->addSubmit('reset', 'Storno') |
||
| 197 | ->setAttribute('class', 'btn-reset') |
||
| 198 | ->onClick[] = [$this, 'processReset']; |
||
| 199 | |||
| 200 | |||
| 201 | $form = $this->setupRendering($form); |
||
| 202 | |||
| 203 | $form->onSuccess[] = [$this, 'processForm']; |
||
| 204 | |||
| 205 | return $form; |
||
| 206 | } |
||
| 207 | |||
| 479 |
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.