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

Introduce an option of dump-autoload to fail on PSR uncompliant classes #10241

Closed
Kolyunya opened this issue Oct 29, 2021 · 8 comments · Fixed by #10886
Closed

Introduce an option of dump-autoload to fail on PSR uncompliant classes #10241

Kolyunya opened this issue Oct 29, 2021 · 8 comments · Fixed by #10886
Labels
Milestone

Comments

@Kolyunya
Copy link

Kolyunya commented Oct 29, 2021

I would like to suggest adding an option to the dump-autoload command which would force it to fail when it encounters PSR uncompliant classes. This would be very profitable to add this kind of validation to the CI scripts.

Currently, the command just prints to the stdout notices like the following but the return code is always 0 thus there's no straightforward way to automate this important validation process.

Class Foo located in ./Foo.php does not comply with psr-4 autoloading standard. Skipping.
@Seldaek
Copy link
Member

Seldaek commented Nov 8, 2021

This is really not so trivial to add IMO.. So sounds like not really worth the trouble to me.

I think it could be done by propagating a list of warnings all the way through AutoloadGenerator::dump and its children and into ClassMapGenerator too, so that DumpAutoloadCommand could easily retreive warnings and exit differently if --strict is passed in for example.

@Seldaek Seldaek added the Feature label Nov 8, 2021
@Seldaek Seldaek added this to the Nice To Have milestone Nov 8, 2021
@temp
Copy link

temp commented Feb 18, 2022

@Seldaek maybe introduce a validate-autoload command? We would like to check for this is in our ci-pipeline, but don't want to parse a dump-autoload run...

@danepowell
Copy link
Contributor

Agreed, and I'd like to see this option anywhere that a warning can be generated. For instance, you can get the PSR-4 warnings on composer install as well. It's hard to have bulletproof CI when problems like this can't be caught.

@Seldaek
Copy link
Member

Seldaek commented Jun 16, 2022

Yeah I got a possible solution in the works - hopefully can wrap this up next week

@Seldaek
Copy link
Member

Seldaek commented Jun 19, 2022

See #10886

Seldaek added a commit to Seldaek/composer that referenced this issue Jun 20, 2022
Seldaek added a commit that referenced this issue Jun 20, 2022
@Kolyunya
Copy link
Author

Kolyunya commented Jun 20, 2022

@Seldaek thank you so much for your work! Looking forward to a stable release to test it out!

@Seldaek
Copy link
Member

Seldaek commented Jun 20, 2022

You can give it a shot with "composer self-update --snapshot" already

@danepowell
Copy link
Contributor

danepowell commented Jun 21, 2022

Thanks! We've already implemented this in our CI to catch tests with bad class names that Composer would otherwise fail to load: acquia/cli#1070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants