-
-
Notifications
You must be signed in to change notification settings - Fork 43
Feature/update php cs fixer 2.8.x #336
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
Feature/update php cs fixer 2.8.x #336
Conversation
.php_cs.dist
Outdated
'ternary_to_null_coalescing' => true, | ||
]) | ||
->setUsingCache(true) | ||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please configure your IDE to always add a newline at end of file, this will make the red pictogram disappear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops I forgot to do it for this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
So we must remove StyleCI integration after merging this? |
project/.php_cs.dist
Outdated
* | ||
* It's auto-generated by sonata-project/dev-kit package. | ||
* | ||
* Package `sllh/php-cs-fixer-styleci-bridge` is required to get it working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still true?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just a bad copy paste from the old file.
.php_cs.dist
Outdated
|
||
return PhpCsFixer\Config::create() | ||
->setFinder($finder) | ||
->setRiskyAllowed(true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this should be true... will it create BC-breaks by e.g. changing signatures to add void
, things like that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I set the setRiskyAllowed
option to true
to use the options below :
- declare_strict_types
- modernize_types_casting
- psr4
- strict_comparison
- strict_param
But is this really necessary for the different Sonata project?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The setRiskyAllowed
can stay here, but we have to filter the risky fixers.
For example, strict_param
and strict_comparison
might introduce BC break on current stables.
.php_cs.dist
Outdated
->setRiskyAllowed(true) | ||
->setRules([ | ||
'@Symfony' => true, | ||
'@Symfony:risky' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do exactly?
Not released from month does not mean this one is not maintained at all. Otherwise, I would put a message about it. 😉
Well, simply because the StyleCI configuration has diverged form php-cs-fixer v2. 😕 soullivaneuh/php-cs-fixer-styleci-bridge#79 And AFAIK, nothing changed on this side. I personnaly 👎 to remove it right know and would like to change the CI instead (I'm working on a new one) to still have one working waiting that. But if the @sonata-project/contributors vote to remove it right know, I'm ok with it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add PHP56Migration:risky
and PHP56Migration
(if exists?`
.php_cs.dist
Outdated
@@ -0,0 +1,60 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make a link to project/.php_cs.dist
or require it we should have the same configuration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use require to the project configuration.
.php_cs.dist
Outdated
'syntax' => 'short', | ||
], | ||
'braces' => [ | ||
'allow_single_line_closure' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it compliant to SF standards?
.php_cs.dist
Outdated
], | ||
'modernize_types_casting' => true, | ||
'no_extra_consecutive_blank_lines' => [ | ||
'break', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this list? Can't we just enable the fixer globally?
.php_cs.dist
Outdated
'throw', | ||
'use', | ||
], | ||
'no_useless_else' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, this one is buggy: PHP-CS-Fixer/PHP-CS-Fixer#2694
.php_cs.dist
Outdated
'phpdoc_order' => true, | ||
'psr4' => true, | ||
'semicolon_after_instruction' => true, | ||
'strict_comparison' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove it. This one may introduce BC breaks.
.php_cs.dist
Outdated
'psr4' => true, | ||
'semicolon_after_instruction' => true, | ||
'strict_comparison' => true, | ||
'strict_param' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove it. This one may introduce BC breaks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we do this, we must have a Travis job to run php-cs-fixer.
.php_cs.dist
Outdated
'ordered_imports' => true, | ||
'phpdoc_order' => true, | ||
'psr4' => true, | ||
'semicolon_after_instruction' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is already included on Symfony
rules set, please remove.
.php_cs.dist
Outdated
'no_useless_return' => true, | ||
'ordered_imports' => true, | ||
'phpdoc_order' => true, | ||
'psr4' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be remove if we keep Symfony:risky
.
web/index.php
Outdated
@@ -9,6 +9,8 @@ | |||
* file that was distributed with this source code. | |||
*/ | |||
|
|||
declare(strict_types=1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this declare
from dev-kit files. It should not be introduced with common cs files.
As PHP 7.1 will be required on next major, we may take benefit to introduce really risky rules when PHP version is 7.1+? |
src/Config/DevKitConfiguration.php
Outdated
@@ -42,8 +42,7 @@ public function getConfigTreeBuilder() | |||
->arrayNode('packages') | |||
->prototype('scalar')->end() | |||
->end() | |||
->end() | |||
; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which rule is doing that? It should not be changed.
'has_projects' => true, | ||
'has_wiki' => false, | ||
'default_branch' => end($branches), | ||
'homepage' => 'https://sonata-project.org/', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Array must not be aligned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of my reviews was outdated since some changes.
Could you please make .php_cs.dist
a symbolic link to project/.php_cs.dist
? Then we ca discuss about the configuration itself. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The project/.travis.yml.twig
file needs to be updated in order to run php-cs-fixer on a single job.
You may add maintainer edit option on this PR if you want me to finish it. 👍
composer.json
Outdated
"symfony/config": "^3.0", | ||
"symfony/console": "^3.0", | ||
"symfony/filesystem": "^3.0", | ||
"symfony/yaml": "^3.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, why not get the latest?
project/.php_cs.dist
Outdated
'header' => $header, | ||
'location' => 'after_open', | ||
], | ||
'no_extra_consecutive_blank_lines' => [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please leave this at true
to keep the Symfony default config.
project/.php_cs.dist
Outdated
return PhpCsFixer\Config::create() | ||
->setFinder($finder) | ||
->setRules([ | ||
'@Symfony' => true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add the following rules sets?
- Symfony:risky
- PHP56Migration
- PHP56Migration:risky
- PHPUnit57Migration:risky
@soullivaneuh I will take time at the lunch break to finalize the last comments. Thank you for your help |
@soullivaneuh I think I have corrected all your requests. By cons I do not feel that it works the symbolic link for the file Do I need to do other PRs in other Sonata projects to remove dependency |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the link does not work, then just require it. The configuration is just PHP code after all, it should work.
What about my comment? #336 (comment)
I may do it if you prefer.
Thank you for the effort.
project/.travis.yml.twig
Outdated
@@ -75,6 +75,7 @@ matrix: | |||
|
|||
before_install: | |||
- git remote add upstream ${UPSTREAM_URL} && git fetch --all | |||
- if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.1/php-cs-fixer.phar; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.travis.yml
Outdated
@@ -14,10 +14,12 @@ cache: | |||
|
|||
before_install: | |||
- phpenv config-rm xdebug.ini | |||
- wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--output-document php-cs-fixer.phar
.php_cs.dist
Outdated
@@ -0,0 +1,60 @@ | |||
<?php |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use require to the project configuration.
@soullivaneuh If you do not mind, I'd really like to finish it myself. For your comment #336, if I understand correctly, you want PHP 7.1 to be required? So I just have to delete the rules for PHP 5.x and add the rules for PHP 7.1 in the .php_cs.dist file? |
No problem, just help proposing. 👍
No. I mean, update the configuration to add the risky rules en PHP migration rules if php-cs-fixer is run under PHP 7.1.
I don't know, it could be fixed on dev-kit PR. @sonata-project/contributors WDYT? In any case, please wait this PR being merged before doing anything.
If you want to do it, you can. But after getting this PR merged and deployed across repositories. |
I found the problem with the symbolic link, it was a simple problem of path. |
.travis.yml
Outdated
@@ -14,10 +14,12 @@ cache: | |||
|
|||
before_install: | |||
- phpenv config-rm xdebug.ini | |||
- wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar --output-document php-cs-fixer.phar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend to download the PHAR from GitHub (https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases) because:
- It is available trough HTTPS
- You can stick to a specific version, it makes the tests more predictable
project/.travis.yml.twig
Outdated
@@ -75,6 +75,7 @@ matrix: | |||
|
|||
before_install: | |||
- git remote add upstream ${UPSTREAM_URL} && git fetch --all | |||
- if [[ $lint = 1 ]]; then wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar --output-document php-cs-fixer.phar; fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe am I missing something, but it looks like the $lint
var is always undefined.
@@ -37,7 +37,7 @@ protected function configure() | |||
*/ | |||
protected function execute(InputInterface $input, OutputInterface $output) | |||
{ | |||
$branchDepth = intval($input->getOption('branch-depth')); | |||
$branchDepth = (int) ($input->getOption('branch-depth')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parenthesis around $input->getOption('branch-depth')
are useless.
For what it's worth, API Platform switched from StyleCI to PHP CS Fixer some times ago too, because PHP CS Fixer is more flexible (especially when using PHP 7+). |
I agree @dunglas, it's quite bad than StyleCI diverged from php-cs-fixer v2. It's also why the bridge I written is hard to maintain. I'm currently trying a work to make a similar tool but running php-cs-fixer (and others) natively. Thanks for the review BTW! 👍 |
@@ -14,10 +14,12 @@ cache: | |||
|
|||
before_install: | |||
- phpenv config-rm xdebug.ini | |||
- wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.8.2/php-cs-fixer.phar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to just download v2
, minor version should be BC.
"vlucas/phpdotenv": "^2.2" | ||
"sebastian/diff": "^2.0", | ||
"silex/silex": "^2.2", | ||
"symfony/config": "^3.3", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why those changes? They are not part of the PR, please revert and just keep php-cs-fixer-styleci-bridge
removal.
'ternary_to_null_coalescing' => true, | ||
]; | ||
|
||
if (\PHP_VERSION_ID >= 50600 && \PHP_VERSION_ID < 70000) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK, we can use the migration below even with PHP7. Please remove \PHP_VERSION_ID < 70000
'@PHP56Migration:risky' => true, | ||
'@PHPUnit57Migration:risky' => true, | ||
]); | ||
} else if (\PHP_VERSION_ID >= 70000 && \PHP_VERSION_ID < 70100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove \PHP_VERSION_ID < 70100
And simple if can be used.
$rules = array_merge($rules, [ | ||
'PHP70Migration:risky' => true, | ||
]); | ||
} else if (\PHP_VERSION_ID >= 70100 && \PHP_VERSION_ID < 70200) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove PHP_VERSION_ID < 70200
and use simple if
.
@@ -49,6 +49,7 @@ matrix: | |||
{% if docs_target %} | |||
- php: '{{ php|last }}' | |||
env: TARGET=lint | |||
env: lint=1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need this variable.
You should instead download php-cs-fixer binary on this file: https://github.com/sonata-project/dev-kit/blob/master/project/.travis/install_lint.sh (you may use the already present composer global require
).
And add the php-cs-fixer command here:
Line 16 in 5d31b22
git diff --exit-code |
--dry-run and the --diff
as we already check the diff at the end.
Sorry for that, I forgot to tell you.
I'll continue and finish your PR in #358, we need it for user-bundle. Thanks a lot for your work! 👍 |
I did not have time to look at it this weekend. Thanks and see you soon on an upcoming pull request ;) |
The project php-cs-fixer-styleci-bridge has not been released for several months.
When you run php-cs-fix in version 2, nothing works.
I propose to you to pass this project directly and the others with a configuration for php-cs-fix version 2.
On the other hand for the configuration I am maybe going a little strong?
Closes #158
Closes #157