Skip to content

Commit cfe069b

Browse files
committed
coding style
1 parent 282a0fa commit cfe069b

22 files changed

+119
-75
lines changed

examples/custom-control.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DateInput extends Nette\Forms\Controls\BaseControl
2929
public function __construct($label = null)
3030
{
3131
parent::__construct($label);
32-
$this->addRule([__CLASS__, 'validateDate'], 'Date is invalid.');
32+
$this->addRule([self::class, 'validateDate'], 'Date is invalid.');
3333
}
3434

3535

@@ -76,20 +76,20 @@ public function getControl()
7676
{
7777
$name = $this->getHtmlName();
7878
return Html::el('input', [
79-
'name' => $name . '[day]',
80-
'id' => $this->getHtmlId(),
81-
'value' => $this->day,
82-
'type' => 'number',
83-
'min' => 1,
84-
'max' => 31,
85-
'data-nette-rules' => Helpers::exportRules($this->getRules()) ?: null,
86-
])
79+
'name' => $name . '[day]',
80+
'id' => $this->getHtmlId(),
81+
'value' => $this->day,
82+
'type' => 'number',
83+
'min' => 1,
84+
'max' => 31,
85+
'data-nette-rules' => Helpers::exportRules($this->getRules()) ?: null,
86+
])
8787

8888
. Helpers::createSelectBox(
89-
[1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
90-
[],
91-
$this->month
92-
)->name($name . '[month]')
89+
[1 => 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
90+
[],
91+
$this->month
92+
)->name($name . '[month]')
9393

9494
. Html::el('input', [
9595
'name' => $name . '[year]',

examples/manual-rendering.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,13 @@
5656

5757
<?php $form->render('begin') ?>
5858

59-
<?php if ($form->errors): ?>
59+
<?php if ($form->errors) { ?>
6060
<ul class="error">
61-
<?php foreach ($form->errors as $error): ?>
61+
<?php foreach ($form->errors as $error) { ?>
6262
<li><?php echo htmlspecialchars($error) ?></li>
63-
<?php endforeach ?>
63+
<?php } ?>
6464
</ul>
65-
<?php endif ?>
65+
<?php } ?>
6666

6767
<fieldset>
6868
<legend>Personal data</legend>

src/Bridges/FormsLatte/Runtime.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public static function renderBlueprint($form): void
8888

8989
public function getLabel($name = null)
9090
{
91-
return $this->inner->getLabel() ? '{label ' . $this->inner->lookupPath(Form::class) . '/}' : null;
91+
return $this->inner->getLabel()
92+
? '{label ' . $this->inner->lookupPath(Form::class) . '/}'
93+
: null;
9294
}
9395

9496

@@ -106,7 +108,9 @@ public function isRequired(): bool
106108

107109
public function getOption($key, $default = null)
108110
{
109-
return $key === 'rendered' ? parent::getOption($key) : $this->inner->getOption($key, $default);
111+
return $key === 'rendered'
112+
? parent::getOption($key)
113+
: $this->inner->getOption($key, $default);
110114
}
111115
};
112116
$dummyInput->inner = $input;

src/Forms/Container.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,12 @@ public function addText(string $name, $label = null, int $cols = null, int $maxL
267267
* Adds single-line text input control used for sensitive input such as passwords.
268268
* @param string|object $label
269269
*/
270-
public function addPassword(string $name, $label = null, int $cols = null, int $maxLength = null): Controls\TextInput
271-
{
270+
public function addPassword(
271+
string $name,
272+
$label = null,
273+
int $cols = null,
274+
int $maxLength = null
275+
): Controls\TextInput {
272276
return $this[$name] = (new Controls\TextInput($label, $maxLength))
273277
->setHtmlAttribute('size', $cols)
274278
->setHtmlType('password');
@@ -388,8 +392,12 @@ public function addSelect(string $name, $label = null, array $items = null, int
388392
* Adds select box control that allows multiple item selection.
389393
* @param string|object $label
390394
*/
391-
public function addMultiSelect(string $name, $label = null, array $items = null, int $size = null): Controls\MultiSelectBox
392-
{
395+
public function addMultiSelect(
396+
string $name,
397+
$label = null,
398+
array $items = null,
399+
int $size = null
400+
): Controls\MultiSelectBox {
393401
return $this[$name] = (new Controls\MultiSelectBox($label, $items))
394402
->setHtmlAttribute('size', $size > 1 ? $size : null);
395403
}

src/Forms/Controls/BaseControl.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public function getLabel($caption = null)
273273
{
274274
$label = clone $this->label;
275275
$label->for = $this->getHtmlId();
276-
$caption = $caption === null ? $this->caption : $caption;
276+
$caption = $caption ?? $this->caption;
277277
$translator = $this->getForm()->getTranslator();
278278
$label->setText($translator && !$caption instanceof Nette\Utils\IHtmlString ? $translator->translate($caption) : $caption);
279279
return $label;
@@ -346,7 +346,13 @@ public function getHtmlId()
346346
public function setHtmlAttribute(string $name, $value = true)
347347
{
348348
$this->control->$name = $value;
349-
if ($name === 'name' && ($form = $this->getForm(false)) && !$this->isDisabled() && $form->isAnchored() && $form->isSubmitted()) {
349+
if (
350+
$name === 'name'
351+
&& ($form = $this->getForm(false))
352+
&& !$this->isDisabled()
353+
&& $form->isAnchored()
354+
&& $form->isSubmitted()
355+
) {
350356
$this->loadHttpData();
351357
}
352358
return $this;
@@ -383,7 +389,9 @@ public function setTranslator(?Nette\Localization\ITranslator $translator)
383389
public function getTranslator(): ?Nette\Localization\ITranslator
384390
{
385391
if ($this->translator === true) {
386-
return $this->getForm(false) ? $this->getForm()->getTranslator() : null;
392+
return $this->getForm(false)
393+
? $this->getForm()->getTranslator()
394+
: null;
387395
}
388396
return $this->translator;
389397
}

src/Forms/Controls/Button.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function getControl($caption = null): Nette\Utils\Html
5858
return $el->addAttributes([
5959
'name' => $this->getHtmlName(),
6060
'disabled' => $this->isDisabled(),
61-
'value' => $this->translate($caption === null ? $this->getCaption() : $caption),
61+
'value' => $this->translate($caption ?? $this->getCaption()),
6262
]);
6363
}
6464
}

src/Forms/Controls/CheckboxList.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,9 @@ public function __construct($label = null, array $items = null)
4949
public function loadHttpData(): void
5050
{
5151
$data = $this->getForm()->getHttpData(Nette\Forms\Form::DATA_TEXT, substr($this->getHtmlName(), 0, -2));
52-
if ($data === null) {
53-
$data = $this->getHttpData(Nette\Forms\Form::DATA_TEXT);
54-
} else {
55-
$data = explode(',', $data);
56-
}
52+
$data = $data === null
53+
? $this->getHttpData(Nette\Forms\Form::DATA_TEXT)
54+
: explode(',', $data);
5755
$this->value = array_keys(array_flip($data));
5856
if (is_array($this->disabled)) {
5957
$this->value = array_diff($this->value, array_keys($this->disabled));

src/Forms/Controls/ChoiceControl.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@ public function loadHttpData(): void
4040
{
4141
$this->value = $this->getHttpData(Nette\Forms\Form::DATA_TEXT);
4242
if ($this->value !== null) {
43-
if (is_array($this->disabled) && isset($this->disabled[$this->value])) {
44-
$this->value = null;
45-
} else {
46-
$this->value = key([$this->value => null]);
47-
}
43+
$this->value = is_array($this->disabled) && isset($this->disabled[$this->value])
44+
? null
45+
: key([$this->value => null]);
4846
}
4947
}
5048

@@ -72,7 +70,9 @@ public function setValue($value)
7270
*/
7371
public function getValue()
7472
{
75-
return array_key_exists($this->value, $this->items) ? $this->value : null;
73+
return array_key_exists($this->value, $this->items)
74+
? $this->value
75+
: null;
7676
}
7777

7878

src/Forms/Controls/CsrfProtection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function getToken(): string
7171
if (!$this->session) {
7272
throw new Nette\InvalidStateException('Session initialization error');
7373
}
74-
$session = $this->session->getSection(__CLASS__);
74+
$session = $this->session->getSection(self::class);
7575
if (!isset($session->token)) {
7676
$session->token = Nette\Utils\Random::generate();
7777
}

src/Forms/Controls/TextBase.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function setValue($value)
5353
*/
5454
public function getValue()
5555
{
56-
$value = $this->value === Strings::trim($this->translate($this->emptyValue)) ? '' : $this->value;
56+
$value = $this->value === Strings::trim($this->translate($this->emptyValue))
57+
? ''
58+
: $this->value;
5759
return $this->nullable && $value === '' ? null : $value;
5860
}
5961

@@ -138,7 +140,9 @@ public function addRule($validator, $errorMessage = null, $arg = null)
138140
if ($validator === Form::LENGTH || $validator === Form::MAX_LENGTH) {
139141
$tmp = is_array($arg) ? $arg[1] : $arg;
140142
if (is_scalar($tmp)) {
141-
$this->control->maxlength = isset($this->control->maxlength) ? min($this->control->maxlength, $tmp) : $tmp;
143+
$this->control->maxlength = isset($this->control->maxlength)
144+
? min($this->control->maxlength, $tmp)
145+
: $tmp;
142146
}
143147
}
144148
return parent::addRule($validator, $errorMessage, $arg);

0 commit comments

Comments
 (0)