Skip to content

Commit 056c21d

Browse files
committed
used PHP 7.1 features
1 parent bad7858 commit 056c21d

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

examples/localization.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function __construct(array $table)
3131
*/
3232
public function translate($message, $count = NULL)
3333
{
34-
return isset($this->table[$message]) ? $this->table[$message] : $message;
34+
return $this->table[$message] ?? $message;
3535
}
3636
}
3737

src/Forms/Container.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ public function __call($name, $args)
477477
public static function extensionMethod($name, $callback = NULL)
478478
{
479479
if (strpos($name, '::') !== FALSE) { // back compatibility
480-
list(, $name) = explode('::', $name);
480+
[, $name] = explode('::', $name);
481481
}
482482
Nette\Utils\ObjectMixin::setExtensionMethod(__CLASS__, $name, $callback);
483483
}

src/Forms/ControlGroup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public function setOption($key, $value)
9797
*/
9898
public function getOption($key, $default = NULL)
9999
{
100-
return isset($this->options[$key]) ? $this->options[$key] : $default;
100+
return $this->options[$key] ?? $default;
101101
}
102102

103103

src/Forms/Controls/BaseControl.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ public function setOption($key, $value)
582582
*/
583583
public function getOption($key, $default = NULL)
584584
{
585-
return isset($this->options[$key]) ? $this->options[$key] : $default;
585+
return $this->options[$key] ?? $default;
586586
}
587587

588588

@@ -611,7 +611,7 @@ public function __call($name, $args)
611611
public static function extensionMethod($name, $callback = NULL)
612612
{
613613
if (strpos($name, '::') !== FALSE) { // back compatibility
614-
list(, $name) = explode('::', $name);
614+
[, $name] = explode('::', $name);
615615
}
616616
Nette\Utils\ObjectMixin::setExtensionMethod(get_called_class(), $name, $callback);
617617
}

src/Forms/Form.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ public function getGroups()
304304
*/
305305
public function getGroup($name)
306306
{
307-
return isset($this->groups[$name]) ? $this->groups[$name] : NULL;
307+
return $this->groups[$name] ?? NULL;
308308
}
309309

310310

@@ -649,9 +649,6 @@ public function __toString()
649649
return $this->getRenderer()->render($this);
650650

651651
} catch (\Throwable $e) {
652-
} catch (\Exception $e) {
653-
}
654-
if (isset($e)) {
655652
if (func_num_args()) {
656653
throw $e;
657654
}

src/Forms/Helpers.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,19 @@ public static function exportRules(Rules $rules)
144144
*/
145145
public static function createInputList(array $items, array $inputAttrs = NULL, array $labelAttrs = NULL, $wrapper = NULL)
146146
{
147-
list($inputAttrs, $inputTag) = self::prepareAttrs($inputAttrs, 'input');
148-
list($labelAttrs, $labelTag) = self::prepareAttrs($labelAttrs, 'label');
147+
[$inputAttrs, $inputTag] = self::prepareAttrs($inputAttrs, 'input');
148+
[$labelAttrs, $labelTag] = self::prepareAttrs($labelAttrs, 'label');
149149
$res = '';
150150
$input = Html::el();
151151
$label = Html::el();
152-
list($wrapper, $wrapperEnd) = $wrapper instanceof Html ? [$wrapper->startTag(), $wrapper->endTag()] : [(string) $wrapper, ''];
152+
[$wrapper, $wrapperEnd] = $wrapper instanceof Html ? [$wrapper->startTag(), $wrapper->endTag()] : [(string) $wrapper, ''];
153153

154154
foreach ($items as $value => $caption) {
155155
foreach ($inputAttrs as $k => $v) {
156-
$input->attrs[$k] = isset($v[$value]) ? $v[$value] : NULL;
156+
$input->attrs[$k] = $v[$value] ?? NULL;
157157
}
158158
foreach ($labelAttrs as $k => $v) {
159-
$label->attrs[$k] = isset($v[$value]) ? $v[$value] : NULL;
159+
$label->attrs[$k] = $v[$value] ?? NULL;
160160
}
161161
$input->value = $value;
162162
$res .= ($res === '' && $wrapperEnd === '' ? '' : $wrapper)
@@ -178,7 +178,7 @@ public static function createSelectBox(array $items, array $optionAttrs = NULL,
178178
if ($selected !== NULL) {
179179
$optionAttrs['selected?'] = $selected;
180180
}
181-
list($optionAttrs, $optionTag) = self::prepareAttrs($optionAttrs, 'option');
181+
[$optionAttrs, $optionTag] = self::prepareAttrs($optionAttrs, 'option');
182182
$option = Html::el();
183183
$res = $tmp = '';
184184
foreach ($items as $group => $subitems) {
@@ -191,7 +191,7 @@ public static function createSelectBox(array $items, array $optionAttrs = NULL,
191191
foreach ($subitems as $value => $caption) {
192192
$option->value = $value;
193193
foreach ($optionAttrs as $k => $v) {
194-
$option->attrs[$k] = isset($v[$value]) ? $v[$value] : NULL;
194+
$option->attrs[$k] = $v[$value] ?? NULL;
195195
}
196196
if ($caption instanceof Html) {
197197
$caption = clone $caption;

src/Forms/Rules.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function addFilter($filter)
174174
$this->rules[] = $rule = new Rule;
175175
$rule->control = $this->control;
176176
$rule->validator = function (IControl $control) use ($filter) {
177-
$control->setValue(call_user_func($filter, $control->getValue()));
177+
$control->setValue($filter($control->getValue()));
178178
return TRUE;
179179
};
180180
return $this;
@@ -282,7 +282,7 @@ public static function validateRule(Rule $rule)
282282
$val = $val instanceof IControl ? $val->getValue() : $val;
283283
}
284284
return $rule->isNegative
285-
xor call_user_func(self::getCallback($rule), $rule->control, is_array($rule->arg) ? $args : $args[0]);
285+
xor self::getCallback($rule)($rule->control, is_array($rule->arg) ? $args : $args[0]);
286286
}
287287

288288

0 commit comments

Comments
 (0)