Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use ternary operators in Helpers #8529

Merged
merged 5 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions system/Helpers/array_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ function _array_search_dot(array $indexes, array $array)
$answer = array_filter($answer, static fn ($value) => $value !== null);

if ($answer !== []) {
if (count($answer) === 1) {
// If array only has one element, we return that element for BC.
return current($answer);
}

return $answer;
// If array only has one element, we return that element for BC.
return count($answer) === 1 ? current($answer) : $answer;
ddevsr marked this conversation as resolved.
Show resolved Hide resolved
}

return null;
Expand Down
8 changes: 1 addition & 7 deletions system/Helpers/form_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,13 +656,7 @@ function set_radio(string $field, string $value = '', bool $default = false): st

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

if ($oldInput !== null) {
$input = $oldInput;
} elseif ($postInput !== null) {
$input = $postInput;
} else {
$input = $default;
}
$input = $oldInput ?? $postInput ?? $default;
ddevsr marked this conversation as resolved.
Show resolved Hide resolved

if (is_array($input)) {
// Note: in_array('', array(0)) returns TRUE, do not use it
Expand Down
6 changes: 3 additions & 3 deletions system/Helpers/html_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ function _list(string $type = 'ul', $list = [], $attributes = '', int $depth = 0
$out .= $val;
} else {
$out .= $key
. "\n"
. _list($type, $val, '', $depth + 4)
. str_repeat(' ', $depth + 2);
. "\n"
. _list($type, $val, '', $depth + 4)
. str_repeat(' ', $depth + 2);
}

$out .= "</li>\n";
Expand Down
Loading