Skip to content

Widen Option::reject() parameter type#80

Open
axlon wants to merge 1 commit intoschmittjoh:masterfrom
axlon:reject-parameter-type
Open

Widen Option::reject() parameter type#80
axlon wants to merge 1 commit intoschmittjoh:masterfrom
axlon:reject-parameter-type

Conversation

@axlon
Copy link

@axlon axlon commented Oct 21, 2025

Currently the following will trigger a PHPStan error:

class Example
{
    private ?string $originalValue = null;

    /**
     * @param \PhpOption\Option<string> $value
     */
    public function updateIfChanged(Option $value): void
    {
        $value = $value->reject($this->originalValue); // Parameter #1 $value of method PhpOption\Option<string>::reject() expects string, string|null given.  

        if ($value->isDefined()) {
            // ...
        }
    }
}

This is because the parameter to reject is typed as the template type T. To fix this issue the parameter type should be changed to mixed to allow for any value, which is what this PR does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments