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

[5.5] Use of argument (un)packing in throw_if/unless helpers #19255

Merged
merged 2 commits into from
May 18, 2017
Merged
Changes from 1 commit
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
12 changes: 6 additions & 6 deletions src/Illuminate/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -893,13 +893,13 @@ function tap($value, $callback = null)
*
* @param bool $boolean
* @param \Throwable|string $exception
* @param string $message
* @param array ...$arguments
* @return void
*/
function throw_if($boolean, $exception, $message = '')
function throw_if($boolean, $exception, ...$arguments)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would rename this to $parameters.

Copy link
Contributor Author

@kduma kduma May 18, 2017

Choose a reason for hiding this comment

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

True. At least I've learned something 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

Uh... I've got that backwards.

I was simply saying that I'd use $parameters because that's what we use all over in our __call methods. I wasn't thinking from a semantic perspective.

From a semantic perspective, $arguments actually makes more sense.

So I take back what I said originally. I now believe that $arguments is actually a better name 🙈

{
if ($boolean) {
throw (is_string($exception) ? new $exception($message) : $exception);
throw (is_string($exception) ? new $exception(...$arguments) : $exception);
}
}
}
Expand All @@ -910,13 +910,13 @@ function throw_if($boolean, $exception, $message = '')
*
* @param bool $boolean
* @param \Throwable|string $exception
* @param string $message
* @param array ...$arguments
* @return void
*/
function throw_unless($boolean, $exception, $message)
function throw_unless($boolean, $exception, ...$arguments)
{
if (! $boolean) {
throw (is_string($exception) ? new $exception($message) : $exception);
throw (is_string($exception) ? new $exception(...$arguments) : $exception);
}
}
}
Expand Down