Skip to content

Return validated value #280

Open
Open
@dbalabka

Description

@dbalabka

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: #281
Psalm support demonstration: https://psalm.dev/r/a439359976

References:

  1. Similar Java implementation: https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/Validate.html#notNull(T)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions