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

TASK: Replace PHPCS with PHP-CS-Fixer to enforce coding guidelines #4949

Open
wants to merge 4 commits into
base: 9.0
Choose a base branch
from

Conversation

bwaidelich
Copy link
Member

@bwaidelich bwaidelich commented Mar 17, 2024

Adds PHP-CS-Fixer as dev dependency as replacement for PHPCS and configures the following rules:

  • PSR12 PSR-12 Coding Guideline – that was previously covered by PHPCS
  • no_unused_imports disallows unused PHP namespace imports
  • ordered_imports requires use statements to be ordered alphabetically

It makes those checks part of our composer:lint script and adds:

  • composer lint:php-cs-fixer to check them and
  • composer lint:php-cs-fixer:fix to fix violations
  • composer lint:fix to fix any linter violations (currently the same)

Resolves: #4580

@bwaidelich
Copy link
Member Author

This build will fail.
Locally I get:

Found 237 of 739 files that can be fixed in 4.083 seconds, 22.000 MB memory used

When I run composer lint:php-cs-fixer:fix it fixes those namespace imports and afterwards I get

Found 0 of 739 files that can be fixed in 0.030 seconds, 18.000 MB memory used

bwaidelich added a commit that referenced this pull request Mar 17, 2024
@mhsdesign
Copy link
Member

Its a bit sad that we really need another dev dependency for this :/

That makes stuff just needless complex 😅

i currently only use phpstan locally to be honest and even ignore phpcs as it slows me down :P

@bwaidelich
Copy link
Member Author

Its a bit sad that we really need another dev dependency for this :/
That makes stuff just needless complex

It's just a dev dependency, it doesn't affect complexity of our code and in the mid-term can even help us to keep complexity lower.
But of course there is a cost attached to any new dependency..

i currently only use phpstan locally to be honest and even ignore phpcs as it slows me down :P

You are free to ignore it, but our CI won't and IMO that's a good thing that helps us to establish a common coding style.
PHPStorm has built-in support for all three quality tools that highlight errors right away. And if configured correctly, it will create code in the same style and fix it.

Long story short: I think it's valuable to have the namespace imports cleaned up by a tool (and it was you that brought this up *g). PHPCS won't be able to do this, and from reading the comments on squizlabs/PHP_CodeSniffer#1106 it will most likely never support it.

Having said this, maybe PHP-CS-Fixer supports the other checks that we currently do with PHPCS, so we could at least replace it!?

@bwaidelich bwaidelich changed the title TASK: Add PHP-CS-Fixer TASK: Replace PHPCS with PHP-CS-Fixer to enforce coding guidelines Mar 18, 2024
@bwaidelich
Copy link
Member Author

Having said this, maybe PHP-CS-Fixer supports the other checks that we currently do with PHPCS, so we could at least replace it!?

That's seems to be the case..
@mhsdesign What do you think of b418924 ?

Note: This is just an experiment. We should all agree if whether want to switch the quality tools

bwaidelich added a commit that referenced this pull request Mar 18, 2024
@mhsdesign
Copy link
Member

Thanks a lot @bwaidelich !

I must say this looks good in my eyes, but i have only used phpstan so far and let php cs be handled by the ci (rather i forget about its existence all the time).

Getting rid of php cs might be a good idea as they have a super slow release cycle and no clear maintainer, which lead to weird hotfixes and lost time in the past.

So overall im not opinionated in which tool to learn / use but do plead for simplicity so 1 tool should be enough 😅

@mhsdesign
Copy link
Member

A super great goal would be imo to then get also rid of our styleci, as i havent figured out how to run it locally and this is currently always a real bummer when developing as i always forget how many spaces before an anonymous function :D.

So if we can reduce the complexity from two linters to only php cs fixer that would great and im happy to assist.

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

Successfully merging this pull request may close these issues.

Adjust linter to report unused namespace imports
2 participants