slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`SlevomatCodingStandard.Namespaces.UnusedUses` cannot handle properties with (nullable) intersection types

kapersoft opened this issue · comments

SlevomatCodingStandard.Namespaces.UnusedUses thinks the imports are unused when property contains (nullable) intersection types.

This code:

<?php

namespace App;

use Symfony\Component\Cache\Adapter\AdapterInterface;
use Symfony\Contracts\Cache\CacheInterface;

class Example
{
    public (AdapterInterface&CacheInterface)|null $cache = null;
}

Results in the following output:

FILE: example.php
-------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Type Symfony\Component\Cache\Adapter\AdapterInterface is not used in this file.
 6 | ERROR | [x] Type Symfony\Contracts\Cache\CacheInterface is not used in this file.
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------

Time: 16ms; Memory: 8MB

Rule config:

<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
    <properties>
        <property name="searchAnnotations" value="true"/>
    </properties>
</rule>

I am using squizlabs/php_codesniffer@3.7.2 and slevomat/coding-standard@8.14.1

Does any have any ideas how to fix this?

I think PHPCS does not support https://wiki.php.net/rfc/dnf_types