Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kapersoft opened this issue Dec 1, 2023 · 1 comment
Labels

Comments

@kapersoft
Copy link

kapersoft commented Dec 1, 2023

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?

@kapersoft kapersoft changed the title SlevomatCodingStandard.Namespaces.UnusedUses.UnusedUse cannot handle properties with (nullable) intersection types SlevomatCodingStandard.Namespaces.UnusedUses cannot handle properties with (nullable) intersection types Dec 1, 2023
@kukulich
Copy link
Contributor

kukulich commented Dec 1, 2023

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

@kukulich kukulich added the PHPCS label Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants