assert
assert copied to clipboard
Return validated value
I've faced the fact that it is required to create temporary variables to validate values:
$firstName = getParam('firstName');
$lastName = getParam('lastName');
Assert::notNull($firstName);
Assert::notNull($lastName);
createCustomer(
$firstName,
$lastName
);
We can rid of temporary variables if the assertion function returns a valid value:
createCustomer(
Assert::notNull(getParam('firstName')),
Assert::notNull(getParam('lastName'))
);
For some of the assertion functions, we can simply return the valid value. The changes should be BC-safe.
Possible implementation: https://github.com/webmozarts/assert/pull/281 Psalm support demonstration: https://psalm.dev/r/a439359976
References:
- Similar Java implementation: https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/Validate.html#notNull(T)