Skip to content

Commit 0b9b713

Browse files
committed
refactoring
1 parent ae60985 commit 0b9b713

File tree

3 files changed

+36
-44
lines changed

3 files changed

+36
-44
lines changed

src/Forms/Container.php

Lines changed: 27 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -233,13 +233,12 @@ public function getForm($need = TRUE)
233233
* @param string label
234234
* @param int width of the control (deprecated)
235235
* @param int maximum number of characters the user may enter
236-
* @return Nette\Forms\Controls\TextInput
236+
* @return Controls\TextInput
237237
*/
238238
public function addText($name, $label = NULL, $cols = NULL, $maxLength = NULL)
239239
{
240-
$control = new Controls\TextInput($label, $maxLength);
241-
$control->setAttribute('size', $cols);
242-
return $this[$name] = $control;
240+
return $this[$name] = (new Controls\TextInput($label, $maxLength))
241+
->setAttribute('size', $cols);
243242
}
244243

245244

@@ -249,13 +248,13 @@ public function addText($name, $label = NULL, $cols = NULL, $maxLength = NULL)
249248
* @param string label
250249
* @param int width of the control (deprecated)
251250
* @param int maximum number of characters the user may enter
252-
* @return Nette\Forms\Controls\TextInput
251+
* @return Controls\TextInput
253252
*/
254253
public function addPassword($name, $label = NULL, $cols = NULL, $maxLength = NULL)
255254
{
256-
$control = new Controls\TextInput($label, $maxLength);
257-
$control->setAttribute('size', $cols);
258-
return $this[$name] = $control->setType('password');
255+
return $this[$name] = (new Controls\TextInput($label, $maxLength))
256+
->setAttribute('size', $cols)
257+
->setType('password');
259258
}
260259

261260

@@ -265,13 +264,12 @@ public function addPassword($name, $label = NULL, $cols = NULL, $maxLength = NUL
265264
* @param string label
266265
* @param int width of the control
267266
* @param int height of the control in text lines
268-
* @return Nette\Forms\Controls\TextArea
267+
* @return Controls\TextArea
269268
*/
270269
public function addTextArea($name, $label = NULL, $cols = NULL, $rows = NULL)
271270
{
272-
$control = new Controls\TextArea($label);
273-
$control->setAttribute('cols', $cols)->setAttribute('rows', $rows);
274-
return $this[$name] = $control;
271+
return $this[$name] = (new Controls\TextArea($label))
272+
->setAttribute('cols', $cols)->setAttribute('rows', $rows);
275273
}
276274

277275

@@ -280,7 +278,7 @@ public function addTextArea($name, $label = NULL, $cols = NULL, $rows = NULL)
280278
* @param string control name
281279
* @param string label
282280
* @param bool allows to upload multiple files
283-
* @return Nette\Forms\Controls\UploadControl
281+
* @return Controls\UploadControl
284282
*/
285283
public function addUpload($name, $label = NULL, $multiple = FALSE)
286284
{
@@ -292,7 +290,7 @@ public function addUpload($name, $label = NULL, $multiple = FALSE)
292290
* Adds control that allows the user to upload multiple files.
293291
* @param string control name
294292
* @param string label
295-
* @return Nette\Forms\Controls\UploadControl
293+
* @return Controls\UploadControl
296294
*/
297295
public function addMultiUpload($name, $label = NULL)
298296
{
@@ -304,21 +302,20 @@ public function addMultiUpload($name, $label = NULL)
304302
* Adds hidden form control used to store a non-displayed value.
305303
* @param string control name
306304
* @param mixed default value
307-
* @return Nette\Forms\Controls\HiddenField
305+
* @return Controls\HiddenField
308306
*/
309307
public function addHidden($name, $default = NULL)
310308
{
311-
$control = new Controls\HiddenField;
312-
$control->setDefaultValue($default);
313-
return $this[$name] = $control;
309+
return $this[$name] = (new Controls\HiddenField)
310+
->setDefaultValue($default);
314311
}
315312

316313

317314
/**
318315
* Adds check box control to the form.
319316
* @param string control name
320317
* @param string caption
321-
* @return Nette\Forms\Controls\Checkbox
318+
* @return Controls\Checkbox
322319
*/
323320
public function addCheckbox($name, $caption = NULL)
324321
{
@@ -331,7 +328,7 @@ public function addCheckbox($name, $caption = NULL)
331328
* @param string control name
332329
* @param string label
333330
* @param array options from which to choose
334-
* @return Nette\Forms\Controls\RadioList
331+
* @return Controls\RadioList
335332
*/
336333
public function addRadioList($name, $label = NULL, array $items = NULL)
337334
{
@@ -341,7 +338,7 @@ public function addRadioList($name, $label = NULL, array $items = NULL)
341338

342339
/**
343340
* Adds set of checkbox controls to the form.
344-
* @return Nette\Forms\Controls\CheckboxList
341+
* @return Controls\CheckboxList
345342
*/
346343
public function addCheckboxList($name, $label = NULL, array $items = NULL)
347344
{
@@ -355,15 +352,12 @@ public function addCheckboxList($name, $label = NULL, array $items = NULL)
355352
* @param string label
356353
* @param array items from which to choose
357354
* @param int number of rows that should be visible
358-
* @return Nette\Forms\Controls\SelectBox
355+
* @return Controls\SelectBox
359356
*/
360357
public function addSelect($name, $label = NULL, array $items = NULL, $size = NULL)
361358
{
362-
$control = new Controls\SelectBox($label, $items);
363-
if ($size > 1) {
364-
$control->setAttribute('size', (int) $size);
365-
}
366-
return $this[$name] = $control;
359+
return $this[$name] = (new Controls\SelectBox($label, $items))
360+
->setAttribute('size', $size > 1 ? (int) $size : NULL);
367361
}
368362

369363

@@ -373,23 +367,20 @@ public function addSelect($name, $label = NULL, array $items = NULL, $size = NUL
373367
* @param string label
374368
* @param array options from which to choose
375369
* @param int number of rows that should be visible
376-
* @return Nette\Forms\Controls\MultiSelectBox
370+
* @return Controls\MultiSelectBox
377371
*/
378372
public function addMultiSelect($name, $label = NULL, array $items = NULL, $size = NULL)
379373
{
380-
$control = new Controls\MultiSelectBox($label, $items);
381-
if ($size > 1) {
382-
$control->setAttribute('size', (int) $size);
383-
}
384-
return $this[$name] = $control;
374+
return $this[$name] = (new Controls\MultiSelectBox($label, $items))
375+
->setAttribute('size', $size > 1 ? (int) $size : NULL);
385376
}
386377

387378

388379
/**
389380
* Adds button used to submit form.
390381
* @param string control name
391382
* @param string caption
392-
* @return Nette\Forms\Controls\SubmitButton
383+
* @return Controls\SubmitButton
393384
*/
394385
public function addSubmit($name, $caption = NULL)
395386
{
@@ -401,7 +392,7 @@ public function addSubmit($name, $caption = NULL)
401392
* Adds push buttons with no default behavior.
402393
* @param string control name
403394
* @param string caption
404-
* @return Nette\Forms\Controls\Button
395+
* @return Controls\Button
405396
*/
406397
public function addButton($name, $caption = NULL)
407398
{
@@ -414,7 +405,7 @@ public function addButton($name, $caption = NULL)
414405
* @param string control name
415406
* @param string URI of the image
416407
* @param string alternate text for the image
417-
* @return Nette\Forms\Controls\ImageButton
408+
* @return Controls\ImageButton
418409
*/
419410
public function addImage($name, $src = NULL, $alt = NULL)
420411
{

src/Forms/Controls/BaseControl.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
namespace Nette\Forms\Controls;
99

1010
use Nette;
11+
use Nette\Forms\Form;
1112
use Nette\Forms\IControl;
13+
use Nette\Forms\Rules;
1214
use Nette\Utils\Html;
13-
use Nette\Forms\Form;
1415

1516

1617
/**
@@ -58,7 +59,7 @@ abstract class BaseControl extends Nette\ComponentModel\Component implements ICo
5859
/** @var bool|NULL */
5960
private $omitted;
6061

61-
/** @var Nette\Forms\Rules */
62+
/** @var Rules */
6263
private $rules;
6364

6465
/** @var Nette\Localization\ITranslator */
@@ -78,7 +79,7 @@ public function __construct($caption = NULL)
7879
$this->control = Html::el('input', ['type' => NULL, 'name' => NULL]);
7980
$this->label = Html::el('label');
8081
$this->caption = $caption;
81-
$this->rules = new Nette\Forms\Rules($this);
82+
$this->rules = new Rules($this);
8283
$this->setValue(NULL);
8384
}
8485

@@ -411,7 +412,7 @@ public function addRule($validator, $message = NULL, $arg = NULL)
411412
* Adds a validation condition a returns new branch.
412413
* @param mixed condition type
413414
* @param mixed optional condition arguments
414-
* @return Nette\Forms\Rules new branch
415+
* @return Rules new branch
415416
*/
416417
public function addCondition($validator, $value = NULL)
417418
{
@@ -424,7 +425,7 @@ public function addCondition($validator, $value = NULL)
424425
* @param IControl form control
425426
* @param mixed condition type
426427
* @param mixed optional condition arguments
427-
* @return Nette\Forms\Rules new branch
428+
* @return Rules new branch
428429
*/
429430
public function addConditionOn(IControl $control, $validator, $value = NULL)
430431
{
@@ -433,7 +434,7 @@ public function addConditionOn(IControl $control, $validator, $value = NULL)
433434

434435

435436
/**
436-
* @return Nette\Forms\Rules
437+
* @return Rules
437438
*/
438439
public function getRules()
439440
{

tests/Forms.Latte/expected/FormMacros.forms.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
<label for="frm-username" title="hello"> <input type="text" name="username" size="10" id="frm-username" title="Hello"> </label>
1919
error
2020
<label for="frm-select"></label>
21-
<select name="select" id="frm-select" title="Hello" size="10"><option value="m">male</option><option value="f">female</option></select>
21+
<select name="select" size="10" id="frm-select" title="Hello"><option value="m">male</option><option value="f">female</option></select>
2222

2323

2424

2525
<br>
2626

27-
<label for="frm-select" title="hello"> <select name="select" id="frm-select" title="Hello" size="10"><option value="m">male</option><option value="f">female</option></select> </label>
27+
<label for="frm-select" title="hello"> <select name="select" size="10" id="frm-select" title="Hello"><option value="m">male</option><option value="f">female</option></select> </label>
2828

2929
<label for="frm-area"></label>
3030
<textarea name="area" id="frm-area" title="Hello" size="10">one&lt;two</textarea>

0 commit comments

Comments
 (0)