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

Upgrade PHP CS Fixer to v2 #8822

Merged
merged 7 commits into from
Mar 17, 2017
Merged

Upgrade PHP CS Fixer to v2 #8822

merged 7 commits into from
Mar 17, 2017

Conversation

keradus
Copy link
Contributor

@keradus keradus commented Mar 8, 2017

Hi.
I have noticed that you updated PHP CS Fixer to be under FriendsOfPHP vendor, which is great !

Let us put it forward - v1 has reached end of life.
This is my proposal how to update it - with all the upgrade needed to use new version.

Commit logs are meaningful, I did changes one by one.

Keep in mind that v2 brings a lot changes in rules and detects more and more violations - even when using same ruleset (like more rules in PSR2 "level"/"set" or same rule now is more powerful to cover more cases). For that, it's also worth to re-apply the rules on the codebase. To try to keep this PR atomic and easy see the changes, I apply the rules in separated PR - #8823 .
Feel free to close any of the PRs.

@magento-cicd2
Copy link
Contributor

magento-cicd2 commented Mar 8, 2017

CLA assistant check
All committers have signed the CLA.

@@ -25,6 +25,8 @@ atlassian*
/.grunt
/Gruntfile.js
/package.json
/.php_cs
/.php_cs.cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the same line in composer's gitignore... No way to specify other path, like var/.php_cs.cache or something, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deafult location of .php_cs.cache is where .php_cs.dist is.

@@ -0,0 +1,50 @@
<?php
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do this file has to be in the root? No other options like .github or .travis folders?

Then please do changes similar to https://github.com/magento/magento2/blame/develop/.htaccess#L225 in both .htaccess and .htaccess.sample.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't change the way where you keep the file. If you want to move it to non-default location and point the location every time you run the PHP CS Fixer from CLI - it's possible, it's up to you. Also, I doubt that this file should be used only on Travis env.
Anyway, change of where you store the file is outside of scope of this PR.

I updated `.htaccess, thanks

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I'm asking whether php-cs-fixer checks any other location besides current folder by default. If not - no need to move configuration file.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keradus please clarify this item and we are done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How config path is determined:

  • path from CLI argument
  • path of what you are fixing (php-cs-fixer fix foo/ -> foo/.php_cs(.dist))
  • current working dir (php-cs-fixer fix foo/ -> .php_cs(.dist))

to work the best when one may want to run tool providing only subfolders, like
php-cs-fixer fix foo/
and then
php-cs-fixer fix bar/
the best DX is when the config file is on cwd level, so root of the project

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :) Too many details, what I needed is if php-cs-fixer can look into some .php_cs/ folder also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no (except when manually passing the config file as parameter)

->exclude('dev/tests/functional/vendor')
->exclude('dev/tests/integration/tmp')
->exclude('dev/tests/integration/var')
->exclude('lib/internal/Cm')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please exclude generated folder also (var/generation was moved to generated).

Some of these paths are irrelevant already but it will not spoil anything and better to be addressed in separate PR or within this PR processing by Magento folks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused is it supposed to be var/generation or generated.
Anyway, indeed. Out of the scope of this PR. it's up to you which paths should be excluded. I only updated the namespaces and so on. Not changing any logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one: https://github.com/magento/magento2/tree/develop/generated

Ok, no objections from my side, could be updated with any other paths later.

.php_cs.dist Outdated
'new_with_braces' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => ['use'],
'no_extra_consecutive_blank_lines' => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick snippet:

php -r 'var_dump(["no" => ["use"], "no" => true]);'
array(1) {
  ["no"]=>
  bool(true)
}

Is there some generator for https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/UPGRADE.md#renamed-rules ? :) Probably should be just ['use'].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I first translated rules - originally rules extra_empty_lines and remove_lines_between_uses were both translated into no_extra_consecutive_blank_lines, but with different config.
Then sort lines in array. Indeed, should be only once.

'concat_space' => ['spacing' => 'one'],
'include' => true,
'new_with_braces' => true,
'no_empty_statement' => true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join_function -> no_alias_functions is missing (or omitted due to changed behavior?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join_function - works only with join function.
new fixer works with dozens of them.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha, I see, and it is not configurable, ok.

->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'one'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

operators_spaces -> binary_operator_spaces is missing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has wider scope

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything undesired/unexpected? It's not an issue if now it fixes more cases than before :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some thinks it change too much operators. eg in this repo i noticed you like to have space around !. Don't know if this is intended or not.
I do not want to define the ruleset you want to use or change paths. Just pure v1->v2 upgrade. If you want to update ruleset, go ahead ;) but it's your decision.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok :) Here we like consistency, not "zero spaces for concat, one space otherwise".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for you ;)
Again, my purpose was not to figure out which ruleset you want to follow, that's part of the community ;) I just took what was in file

'ordered_imports' => true,
'standardize_not_equals' => true,
'ternary_operator_spaces' => true,
]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except mentioned ruleset is identical 👍

@keradus
Copy link
Contributor Author

keradus commented Mar 10, 2017

Funny there are random Travis failures in this repo...

@orlangur
Copy link
Contributor

0 => 'Your password reset link has expired.'

Aha, didn't see this error before, probably this test relies on system time.

@orlangur
Copy link
Contributor

LGTM 🥇

I don't think anybody could do php-cs-fixer upgrade better.

Now let's wait for Fabien come here and say we are using outdated Symfony components and then I could say I saw everything in my life :)

@keradus
Copy link
Contributor Author

keradus commented Mar 10, 2017

Thank you.
Having approval, I signed CLA.

@keradus
Copy link
Contributor Author

keradus commented Mar 15, 2017

So... could this be merged then ?

@okorshenko okorshenko self-assigned this Mar 16, 2017
@okorshenko okorshenko added this to the March 2017 milestone Mar 16, 2017
@magento-team magento-team merged commit bd1a8cd into magento:develop Mar 17, 2017
@okorshenko
Copy link
Contributor

@keradus thank you for your contribution!
@orlangur thank you for review!

@keradus keradus deleted the cs_fixer branch March 18, 2017 10:37
magento-devops-reposync-svc pushed a commit that referenced this pull request Apr 9, 2024
…op-sync-03072024

Cia 2.4.7 develop 2.4 develop sync 03072024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants