-
Notifications
You must be signed in to change notification settings - Fork 147
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
Return validated value #280
Comments
I'm looking for this feature as well, and this would be helpful for every method. Your example is precisely my use case. The fluent notation makes it much more cleaner to use. Your current PR is only the |
@frankdekker, I will add support for other methods as well if the maintainer accepts that such a feature is required. We should wait for @webmozart's reply. |
I think that Assert should be used inside the public function createCustomer(mixed $firstName, mixed $lastName): void
{
Assert::stringNotEmpty($firstName);
Assert::stringNotEmpty($lastName);
// And then database write, or whatever
} The usage suggested by OP promotes using Assert (and thus, Throwable) as a validation tool, which is not how this package was intended to be used. Throws are far too costly in PHP to be used for validation. |
@shadowhand , that is an interesting idea. Unfortunately, the |
I've faced the fact that it is required to create temporary variables to validate values:
We can rid of temporary variables if the assertion function returns a valid value:
For some of the assertion functions, we can simply return the valid value. The changes should be BC-safe.
Possible implementation: #281
Psalm support demonstration: https://psalm.dev/r/a439359976
References:
The text was updated successfully, but these errors were encountered: