-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Backfill Parameters #3938
Backfill Parameters #3938
Conversation
Rebasing 4.1 and trying again. |
Looks good! @paulbalandan you still around by chance? |
Since this was approved in the other PR I am going to proceed with the merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was influenced by PHPStan's extra strict rules in that empty()
implies weak comparison and we should strive to be more specific what 'emptiness' we are checking. We already have a rector rule that changes empty
checks on arrays to === []
and I believe we should do the same for scalar types.
{ | ||
if (empty($alias)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (empty($alias)) | |
if ($alias === '') |
{ | ||
if (empty($alias)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameter: alias.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new InvalidArgumentException('You must supply the parameter: alias.'); | |
throw new InvalidArgumentException('You must supply the parameter: alias.'); // @codeCoverageIgnore |
if (empty($uri) || empty($userAgent)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (empty($uri) || empty($userAgent)) | |
{ | |
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.'); | |
} | |
if ($uri === null || $userAgent === null) | |
{ | |
throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.'); // @codeCoverageIgnore | |
} |
{ | ||
if (empty($origWidth) || empty($origHeight)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.'); | |
throw new InvalidArgumentException('You must supply the parameters: origWidth, origHeight.'); // @codeCoverageIgnore |
@@ -352,13 +353,18 @@ public function required($str = null): bool | |||
* required_with[password] | |||
* | |||
* @param string|null $str | |||
* @param string $fields List of fields that we should check if present | |||
* @param string|null $fields List of fields that we should check if present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param string|null $fields List of fields that we should check if present | |
* @param string $fields List of fields that we should check if present |
public function required_with($str = null, string $fields = null, array $data = []): bool | ||
{ | ||
if (is_null($fields) || empty($data)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameters: fields, data.'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function required_with($str = null, string $fields = null, array $data = []): bool | |
{ | |
if (is_null($fields) || empty($data)) | |
{ | |
throw new InvalidArgumentException('You must supply the parameters: fields, data.'); | |
} | |
public function required_with($str = null, string $fields = '', array $data = []): bool | |
{ | |
if ($fields === '' || $data === []) | |
{ | |
throw new InvalidArgumentException('You must supply the parameters: fields, data.'); // @codeCoverageIgnore | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below, $fields
is allowed to be an empty string so we need to add the null
option. This could probably be addressed on calling classes but it is also possible that someone is calling this directly (though I really hope not).
* @param string|null $fields | ||
* @param array $data | ||
* | ||
* @return boolean | ||
*/ | ||
public function required_without($str = null, string $fields, array $data): bool | ||
public function required_without($str = null, string $fields = null, array $data = []): bool | ||
{ | ||
if (is_null($fields) || empty($data)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameters: fields, data.'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment with required_with
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = null): bool | ||
{ | ||
if (is_null($data)) | ||
{ | ||
throw new InvalidArgumentException('You must supply the parameter: data.'); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = null): bool | |
{ | |
if (is_null($data)) | |
{ | |
throw new InvalidArgumentException('You must supply the parameter: data.'); | |
} | |
protected function processRules(string $field, string $label = null, $value, $rules = null, array $data = []): bool | |
{ | |
if ($data === []) | |
{ | |
throw new InvalidArgumentException('You must supply the parameter: data.'); // @codeCoverageIgnore | |
} | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one has to add null
as an input option because []
is actually valid input and we're trying to catch cases where the parameter was not supplied at all.
Oh man! I was a little too late. 😂 |
Ah sorry! Those are good changes. I am working on the class aliases but I'll get these done up later today or tomorrow. |
Did this PR also cover functions with nullable optional arguments (or typed arguments that default to |
What is wrong with nullable optional parameters? This PR dealt with the deprecated use of mandatory parameters following optional ones. |
Sorry for the confusion, I will try to elaborate: However, according to the link provided in the referenced issue, PHP8 will not show such message in the following case (typed optional argument defaulting to null): As far as I understand the deprecation, this type of argument list would still be incorrect, although it does not trigger the deprecation message. Therefore I was asking whether the selection of functions targeted by this PR was based on the PHP8 deprecation messages or if all functions with optional parameters before required ones have been changed. Hope this makes it clearer :-) |
While I would like to see that category changed as well, the focus of this PR was actual deprecation notices as they arose during PHP 8 testing. I am unhappy that these parameter inputs exist to begin with, but without breaking the methods for all users we can't really change that in a clean way. If you identify any of the above and want to submit a non-breaking PR we could certainly resolve. I'll be honest I didn't know that was a separate category! |
Description
This PR addresses the now-deprecated(PHP 8) use of mandatory parameters following optional parameters. Split off from #3931.
Checklist: