kubawerlos / php-cs-fixer-custom-fixers

A set of custom fixers for PHP CS Fixer
MIT License
211 stars 19 forks source link

StringableInterfaceFixer rule adds unnecessary Stringable to implements list #923

Closed Arkemlar closed 10 months ago

Arkemlar commented 11 months ago

I have Interface A:

use App\PhpExtension\EqualityInterface;
use JsonSerializable;
use Stringable;

interface Money extends JsonSerializable, Stringable, EqualityInterface
{
}

and class that implements it:

class MoneyWrapper implements Money
{
}

and php-cs-fixer with config:

    ->setRules([
        ...
        PhpCsFixerCustomFixers\Fixer\StringableInterfaceFixer::name() => true,
    ])

Now when I run php-cs-fixer fix it changes my class to this:

use Stringable;

class MoneyWrapper implements Money, Stringable
{
}

This is wrong behaivor, it must not add Stringable to the class since interface it implements already extends from Stringable.

Arkemlar commented 11 months ago

And IDE shows me reasonable error изображение

kubawerlos commented 10 months ago

Hi @Arkemlar,

PHP CS Fixer works on a per-file basis and cannot determine what are the relations between interfaces outside of the file it is currently fixing, thus it is not possible to discover the situation you have described.

Moreover, this is not a bug, it is a false positive of PHPStorm: https://youtrack.jetbrains.com/issue/WI-50862

As it was reported 4 years ago and is still not fixed I've actually have an idea, take a look at https://github.com/kubawerlos/php-cs-fixer-custom-fixers/pull/926

Arkemlar commented 10 months ago

@kubawerlos Thank you for fix, could you please explain how it works?

kubawerlos commented 10 months ago

Well, since there is actually no bug, there is not really a fix for it.

The improvement is exactly what the title of https://github.com/kubawerlos/php-cs-fixer-custom-fixers/pull/926 says.