rectorphp / rector-symfony

Rector upgrade rules for Symfony
http://getrector.com
MIT License
179 stars 86 forks source link

[Symfony 6.4] Add DataTransformerInterface return types #624

Closed TomasVotruba closed 2 months ago

TomasVotruba commented 2 months ago

Ref https://github.com/rectorphp/rector-symfony/issues/537

trsteel88 commented 2 months ago

@TomasVotruba is this forcing a return type on DataTransformers in symfony?

I have the following

public function reverseTransform(mixed $value): ?string
    {
        if (null === $value || '' === (string) $value) {
            return null;
        }

        return 'foo';
    }

But rector is changing this to:

public function reverseTransform(mixed $value): object|string
    {
        if (null === $value || '' === (string) $value) {
            return null;
        }

        return 'foo';
    }

But this isn't correct. It can only be ?string so now I have PHPStan failing on me:

::reverseTransform() should return object|string but returns null.  
trsteel88 commented 2 months ago

Ah using the 71 set instead of 64 fixed it.

$rectorConfig->import(Rector\Symfony\Set\SymfonySetList::SYMFONY_71);