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

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

Closed
ruudk opened this issue Jul 2, 2024 · 9 comments · Fixed by #148
Closed

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

ruudk opened this issue Jul 2, 2024 · 9 comments · Fixed by #148
Labels
enhancement New feature or request

Comments

@ruudk
Copy link

ruudk commented Jul 2, 2024

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
Copy link
Member

janedbal commented Jul 2, 2024

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

@ruudk
Copy link
Author

ruudk commented Jul 2, 2024

@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
Copy link
Author

ruudk commented Jul 2, 2024

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

@janedbal
Copy link
Member

janedbal commented Jul 2, 2024

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
Copy link
Author

ruudk commented Jul 2, 2024

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
Copy link
Member

janedbal commented Jul 2, 2024

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

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

@janedbal janedbal added the enhancement New feature or request label Jul 2, 2024
@ruudk
Copy link
Author

ruudk commented Jul 2, 2024

@janedbal It works 🎉 ⚡ Thank you!!

@ruudk
Copy link
Author

ruudk commented Jul 2, 2024

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

@janedbal
Copy link
Member

janedbal commented Jul 2, 2024

Released as 1.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants