nunomaduro / phpinsights

🔰 Instant PHP quality checks from your console
https://phpinsights.com
MIT License
5.3k stars 281 forks source link

False Detection of Unused Uses with PHP8.1 Intersection Types #619

Closed renky closed 1 year ago

renky commented 1 year ago
Q A
Bug report? yes
Feature request? no
Library version 2.6.1

Insights detecs a false unused uses error with php 8.1 intersection types

Code example:

Contract1.php:

<?php

namespace App\Contracts;

interface Contract1
{

}

Contract2.php:

<?php

namespace App\Contracts;

interface Contract2
{

}

Model.php

<?php

namespace App;

use App\Contracts\Contract1;
use App\Contracts\Contract2;

class Model
{
    public function test(Contract1&Contract2 $test): bool
    {
        return ($test?->test !== null);
    }
}

this leads to the following error:

• [Style] Unused uses:
  Model.php:5: Type App\Contracts\Contract1 is not used in this file.

but Contract1 and 2 are used

renky commented 1 year ago

This problem is solved with the current dev-master - it seems to be solved with a newer slevomat/coding-standard version - with devmaster currently 8.8.0 is used.

it would be great if you release a new version on current master branch if there is no reason to retain a new version

cmgmyr commented 1 year ago

I just tagged v2.7.0 with the fix in master. Please let me know if the issue persists.

renky commented 1 year ago

thanks - it seems to work...