Coding-standard: Unused sniff broken with version 7.0.7 when using classes that extends Enum

Created on 3 May 2021  路  5Comments  路  Source: slevomat/coding-standard

If I use 7.0.7 it wants to remove unused use statements from multiple of my classes while they are indeed used. It looks like it only happens with specific use statements. All classes that extends Enum are getting removed because it says it's not being used (I use https://github.com/myclabs/php-enum),

An example enum class:


namespace MyTypes;

use MyCLabs\Enum\Enum;

/**
 * Action enum
 */
final class Action extends Enum
{
    private const VIEW = 'view';
    private const EDIT = 'edit';
}

It's then being used as: Action::VIEW(). I do use it in combination with named arguments.

So like:

new SomeClass(
    foobar: Action::VIEW(),
);

I could provide more information if needed. Just let me know.

Bug

Most helpful comment

All 5 comments

@Ilyes512 What's removed from the code you posted? The line with use MyCLabs\Enum\Enum; ?

It's removed from a file where I try to use Action. So for example:

<?php

use MyTypes\Action;

class Foobar
{
    public function foo()
    {
        return new Acme(
            mytype: Action::VIEW(),
        );
    }
}

So in the above pseodo code it would remove this line use MyTypes\Action;.

Confirming that when I use dev-master it seems to be fixed :) Damm your fast! Thanks and I appreciate your work!

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings