Skip to content

Commit 4c9bf0e

Browse files
authored
Merge pull request #8529 from ddevsr/refactor-possible-oneliner
refactor: use ternary operators in Helpers
2 parents 206d1ae + aed6e96 commit 4c9bf0e

File tree

3 files changed

+6
-16
lines changed

3 files changed

+6
-16
lines changed

system/Helpers/array_helper.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,8 @@ function _array_search_dot(array $indexes, array $array)
7272
$answer = array_filter($answer, static fn ($value) => $value !== null);
7373

7474
if ($answer !== []) {
75-
if (count($answer) === 1) {
76-
// If array only has one element, we return that element for BC.
77-
return current($answer);
78-
}
79-
80-
return $answer;
75+
// If array only has one element, we return that element for BC.
76+
return count($answer) === 1 ? current($answer) : $answer;
8177
}
8278

8379
return null;

system/Helpers/form_helper.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -656,13 +656,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st
656656

657657
$postInput = $request->getPost($field);
658658

659-
if ($oldInput !== null) {
660-
$input = $oldInput;
661-
} elseif ($postInput !== null) {
662-
$input = $postInput;
663-
} else {
664-
$input = $default;
665-
}
659+
$input = $oldInput ?? $postInput ?? $default;
666660

667661
if (is_array($input)) {
668662
// Note: in_array('', array(0)) returns TRUE, do not use it

system/Helpers/html_helper.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ function _list(string $type = 'ul', $list = [], $attributes = '', int $depth = 0
7070
$out .= $val;
7171
} else {
7272
$out .= $key
73-
. "\n"
74-
. _list($type, $val, '', $depth + 4)
75-
. str_repeat(' ', $depth + 2);
73+
. "\n"
74+
. _list($type, $val, '', $depth + 4)
75+
. str_repeat(' ', $depth + 2);
7676
}
7777

7878
$out .= "</li>\n";

0 commit comments

Comments
 (0)