Skip to content

refactor: use ternary operators in Helpers - #8529

Merged
kenjis merged 5 commits into
codeigniter4:developfrom
ddevsr:refactor-possible-oneliner
Feb 12, 2024
Merged

kenjis merged 5 commits into
codeigniter4:developfrom
ddevsr:refactor-possible-oneliner

Conversation

@ddevsr

@ddevsr ddevsr commented Feb 9, 2024

Copy link
Copy Markdown
Collaborator

Description
Just refactor to one liner.

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@ddevsr ddevsr added the refactor Pull requests that refactor code label Feb 9, 2024
Comment thread system/Helpers/filesystem_helper.php Outdated
Comment thread system/Helpers/form_helper.php
Comment thread system/Helpers/array_helper.php
@michalsn

michalsn commented Feb 9, 2024

Copy link
Copy Markdown
Member

I agree with @kenjis. I'm against micro-optimization that sacrifices the readability and maintainability of code.

@ddevsr
ddevsr force-pushed the refactor-possible-oneliner branch from c521ed7 to 11db748 Compare February 10, 2024 02:00
Comment thread system/Helpers/html_helper.php Outdated
. _list($type, $val, '', $depth + 4)
. str_repeat(' ', $depth + 2);
}
$out .= ! is_array($val) ? $val : $key . "\n" . _list($type, $val, '', $depth + 4) . str_repeat(' ', $depth + 2);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/html_helper.php Outdated
} else {
$img .= ' src="' . slash_item('baseURL') . $src['src'] . '"';
}
$img .= $indexPage === true ? ' src="' . site_url($src['src']) . '"' : ' src="' . slash_item('baseURL') . $src['src'] . '"';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/html_helper.php Outdated
} else {
$script .= 'src="' . slash_item('baseURL') . $v . '" ';
}
$script .= $indexPage === true ? 'src="' . site_url($v) . '" ' : 'src="' . slash_item('baseURL') . $v . '" ';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/html_helper.php Outdated
} else {
$video .= ' src="' . slash_item('baseURL') . $src . '"';
}
$video .= _has_protocol($src) ? ' src="' . $src . '"' : ($indexPage === true ? ' src="' . site_url($src) . '"' : ' src="' . slash_item('baseURL') . $src . '"');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/html_helper.php Outdated
} else {
$audio .= ' src="' . slash_item('baseURL') . $src . '"';
}
$audio .= _has_protocol($src) ? ' src="' . $src . '"' : ($indexPage === true ? ' src="' . site_url($src) . '"' : ' src="' . slash_item('baseURL') . $src . '"');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/text_helper.php Outdated
} else {
$output .= $line . "\n";
}
$output .= $temp !== '' ? $temp . "\n" . $line . "\n" : $line . "\n";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

Comment thread system/Helpers/text_helper.php Outdated
} else {
$end = mb_substr($str, -($maxLength - mb_strlen($beg)));
}
$end = $position === 1 ? mb_substr($str, 0, -($maxLength - mb_strlen($beg))) : mb_substr($str, -($maxLength - mb_strlen($beg)));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this change.

@kenjis kenjis left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@kenjis kenjis changed the title refactor: possible one liner in Helper refactor: use ternary operators in Helpers Feb 10, 2024
@kenjis
kenjis merged commit 4c9bf0e into codeigniter4:develop Feb 12, 2024
@kenjis

kenjis commented Feb 12, 2024

Copy link
Copy Markdown
Member

@ddevsr Thank you!

@ddevsr
ddevsr deleted the refactor-possible-oneliner branch February 12, 2024 09:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Pull requests that refactor code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants