Skip to content

SlevomatCodingStandard.Namespaces.UnusedUses mistakenly reports E_ALL #1038

@morozov

Description

@morozov
$ composer show | grep -P 'coding-standard|php_codesniffer'

doctrine/coding-standard                       8.0.0   The Doctrine Coding Standard is a ...
slevomat/coding-standard                       6.3.8   Slevomat Coding Standard for PHP_C...
squizlabs/php_codesniffer                      3.5.5   PHP_CodeSniffer tokenizes PHP, Jav...

Consider the following code example:

<?php

namespace Foo;

use const E_ALL;
use const E_NOTICE;

echo E_ALL & ~E_NOTICE;

The following violation is reported:

FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Type E_ALL is not used in this file.
   |       |     (SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse)
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

After a fix, the file will look like this:

<?php

namespace Foo;

use const E_NOTICE;

echo E_ALL & ~E_NOTICE;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions