DEVSENSE / phptools-docs

PHP Tools public content
Apache License 2.0
75 stars 9 forks source link

False-positive references #580

Open jameslkingsley opened 1 week ago

jameslkingsley commented 1 week ago

If I lookup the references to a function, PHP tools will show me false-positives in cases where no types could be determined.

Example of this is where you have mocks in a test that are testing a completely unrelated class:

So I have a trait such as:

trait UsesAttributes
{
    public function getAttribute(string $type)
    {
        ...
    }
}

And then somewhere completely unrelated in a test:

$thing = Mockery::mock(Thing::class);
$thing->expects()->getAttribute('id')->atLeast()->once()->andReturns(1);

Even though it's using a method named getAttribute, it has nothing to do with the trait, it doesn't use it at all. Yet PHP tools tries to be clever and assumes this test is making use of it.

There needs to be a setting to only consider references to things when there is absolute confidence in the types being used.

jakubmisek commented 1 week ago

Thank you for pointing this out.

Internally, we know how confident the reference is (it's used during rename refactoring for example). When finding all the references, we wanted to highlight all the potential ones, so we don't miss any (most PHP code is not annotated well so users would miss a lot of references). Sadly there is no way in VSCode to distinguish between potential and solid reference.

We can add a setting, or maybe change the default behavior.

jameslkingsley commented 1 week ago

Yeah a setting would be ideal I think. Depends on the maturity of the codebase, which in my case I'm happy for that tradeoff of potentially missing some older code