symfony / recipes

Symfony Recipes Repository
https://github.com/symfony/recipes/blob/flex/main/RECIPES.md
MIT License
978 stars 480 forks source link

Please follow PSR12 in symfony/framework-bundle and phpunit/phpunit #1220

Closed gremo closed 1 year ago

gremo commented 1 year ago

Related to php_codesniffer contrib recipe: https://github.com/symfony/recipes-contrib/issues/1526.

Some files installed using Flex are not following PSR12, for example:

The fix is trivial, errors are caused by:

Running vendor/bin/phpcs:

root@967b5351a8f9:/var/www/html# vendor/bin/phpcs

FILE: config/preload.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 3 | ERROR | [x] Expected at least 1 space before "."; 0 found
 3 | ERROR | [x] Expected at least 1 space after "."; 0 found
 4 | ERROR | [x] Expected at least 1 space before "."; 0 found
 4 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: public/index.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space before "."; 0 found
 5 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
root@967b5351a8f9:/var/www/html# vendor/bin/phpcs

FILE: config/preload.php
----------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 3 | ERROR | [x] Expected at least 1 space before "."; 0 found
 3 | ERROR | [x] Expected at least 1 space after "."; 0 found
 4 | ERROR | [x] Expected at least 1 space before "."; 0 found
 4 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: public/index.php
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 1 LINE
----------------------------------------------------------------------
 5 | ERROR | [x] Expected at least 1 space before "."; 0 found
 5 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: tests/bootstrap.php
----------------------------------------------------------------------
FOUND 8 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------
  5 | ERROR | [x] Expected at least 1 space before "."; 0 found
  5 | ERROR | [x] Expected at least 1 space after "."; 0 found
  7 | ERROR | [x] Expected at least 1 space before "."; 0 found
  7 | ERROR | [x] Expected at least 1 space after "."; 0 found
  8 | ERROR | [x] Expected at least 1 space before "."; 0 found
  8 | ERROR | [x] Expected at least 1 space after "."; 0 found
 10 | ERROR | [x] Expected at least 1 space before "."; 0 found
 10 | ERROR | [x] Expected at least 1 space after "."; 0 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------
derrabus commented 1 year ago

They follow Symfony's coding standard which predates PSR-12. But once those PHP files have been dumped into your project, you own them and you can have them reformatted according to your preferences.

gremo commented 1 year ago

I see... ok then, if updating to PSR12 is something completly out of question 👍

What do you think about https://github.com/symfony/recipes-contrib/issues/1526?

EDIT

Let's clarify what I mean. I perfectly know I can create my own standard and it's fine.

But from a DX perspective (and DX is something promoted by Symfony) it's somehow confusing for a new developer to:

Just my feeling. I think either Symfony recipes files or the phpcs recipes should accomodate this change.

Otherwise, feel free to close this 👍

derrabus commented 1 year ago
  • Being happy with it and install phpcs with it's "unofficial" contrib recipe (even if "unofficial"... it's still checked a lot by the Symfony team, isn't it?)

Symfony recommends PHP CS Fixer instead of CodeSniffer and that recipe should be in sync with Symfony's CS. But again, using CodeSniffer and PSR-12 is absolutely fine. Just run PHPCBF once and live happily ever after.

wouterj commented 1 year ago

I agree with @derrabus. For files maintained by the Symfony project, it makes sense they use the Symfony CS (which is very similar to the PSR ones, but not 100% equal as you can see).

I would be happy to accept a PR that configures the CBF recipe to follow the Symfony CS.

gremo commented 1 year ago

It's ok then, thank you both for the clarification!