shipmonk-rnd / composer-dependency-analyser

🚀 Fast detection of composer dependency issues (unused dependencies, shadow dependencies, misplaced dependencies)
MIT License
400 stars 10 forks source link

[Fix] unmatched qualified name ::class|const|function #145

Closed instabledesign closed 3 months ago

instabledesign commented 3 months ago

Hi, i Discover this cool project yesterday, so i used it on a Symfony project. And the result of unused dependencies seems to fail matching the qualified name like in this file

so the purpose of this PR is to match the qualified name syntax the new matching rule is T_NAME_QUALIFIED(T_COMMENT, T_DOC_COMMENT)*T_DOUBLE_COLON T_NAME_QUALIFIED follow by next active token(not commented ones) T_DOUBLE_COLON

see the UsedSymbolExtractor::isNextActiveTokenType function to match this one

// Qualified name without use statement
echo Foo\Bar::class;
echo Foo2\Baz::MY_CONST;
echo Foo2\Baz::my_function();

echo Foo\Bar//com
::class;
echo Foo2\Baz//com
::MY_CONST;
echo Foo2\Baz//com
::my_function();

echo Foo\Bar/*com*/::class;
echo Foo2\Baz/*com*/::MY_CONST;
echo Foo2\Baz/*com*/::my_function();

echo Foo\Bar/**doccom*/::class;
echo Foo2\Baz/**doccom*/::MY_CONST;
echo Foo2\Baz/**doccom*/::my_function();

I hope my contribution was clean and useful.

Have a nice coding day 👨🏻‍💻

janedbal commented 3 months ago

seems to fail matching the qualified name like in this file

Files without namespace and use statements have limited support as stated in readme. Trying to make this work has significant other consequences (as you can see from failed E2E tests). I dont think there is an easy way around that.

janedbal commented 3 months ago

And even if we try, supporting only subset of occurrences (like those you tried to fix, followed by :) is definitelly not a way to go.

instabledesign commented 3 months ago

yeah i agree, we should match all or nothing. I thinks only drop support of <php8.1 (EOF at end of 2024) should be the good way to go.

Thank for your answer. Feel free to close this PR, or maybe create a milestone 8.1+ :)

janedbal commented 3 months ago

This should work since 1.6 🎉