php-option icon indicating copy to clipboard operation
php-option copied to clipboard

Widen `Option::reject()` parameter type

Open axlon opened this issue 2 months ago • 0 comments

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.

axlon avatar Oct 21 '25 13:10 axlon