shipmonk-rnd / composer-dependency-analyser

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

Add support for scanning inside Symfony's bundles.php #146

Closed ruudk closed 2 weeks ago

ruudk commented 2 weeks ago

In my Symfony Application, we have a config/bundles.php that looks like this:

<?php

declare(strict_types=1);

return [
    Symfonycasts\TailwindBundle\SymfonycastsTailwindBundle::class => ['all' => true],
    Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
];

My configuration looks like this:

<?php

use ShipMonk\ComposerDependencyAnalyser\Config\Configuration;

$config = new Configuration();
$config->addPathToScan(__DIR__ . '/config/bundles.php', isDev: false);

return $config;

But even though those bundles are used, the analyzer complains:

$ vendor/bin/composer-dependency-analyser

Using config composer-dependency-analyser.php

Found unused dependencies!
(those are listed in composer.json, but no usage was found in scanned paths)

  • symfony/stimulus-bundle
  • symfonycasts/tailwind-bundle

Am I missing something, or is a FQCN class reference not seen as usage?

janedbal commented 2 weeks ago

Files without namespace and use statements have limited support as stated in readme. So just use FQN or use statements.

ruudk commented 2 weeks ago

@janedbal Hmm, interesting. When you have a bundles.php file with 50 bundles, having to import all them, makes the file 100+ lines instead of 50 lines. So I would prefer not to have to do that.

Would it be possible to improve this limited support?

ruudk commented 2 weeks ago

If it is, I could try to provide a PR for it.

janedbal commented 2 weeks ago

When you have a bundles.php file with 50 bundles, having to import all them, makes the file 100+ lines instead of 50 lines. So I would prefer not to have to do that.

So use FQN like this:

<?php

return [
    \Symfonycasts\TailwindBundle\SymfonycastsTailwindBundle::class => ['all' => true],
    \Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
];

Would it be possible to improve this limited support?

Definitelly not easy. I'll try to think about that again.

ruudk commented 2 weeks ago

So use FQN like this:

<?php

return [
    \Symfonycasts\TailwindBundle\SymfonycastsTailwindBundle::class => ['all' => true],
    \Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
];

That works, although PHPStorm / PHP CS Fixer now automatically imports it. Not ideal.

janedbal commented 2 weeks ago

Ok, I dived into it and turns out it was quite easy (#148).

Can you try dev-master if that works for you? Thanks

ruudk commented 2 weeks ago

@janedbal It works 🎉 ⚡ Thank you!!

ruudk commented 2 weeks ago

If you have time, it would be great to have it tagged too.

janedbal commented 2 weeks ago

Released as 1.6.0