Skip to content

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

Closed
wants to merge 25 commits into from
Closed

Feature/update php cs fixer 2.8.x #336

wants to merge 25 commits into from

Conversation

toofff
Copy link
Contributor

@toofff toofff commented Nov 10, 2017

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

.php_cs.dist Outdated
'ternary_to_null_coalescing' => true,
])
->setUsingCache(true)
;
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@core23
Copy link
Member

core23 commented Nov 10, 2017

So we must remove StyleCI integration after merging this?

*
* It's auto-generated by sonata-project/dev-kit package.
*
* Package `sllh/php-cs-fixer-styleci-bridge` is required to get it working.
Copy link
Member

Choose a reason for hiding this comment

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

This is still true?

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's just a bad copy paste from the old file.

.php_cs.dist Outdated

return PhpCsFixer\Config::create()
->setFinder($finder)
->setRiskyAllowed(true)
Copy link
Contributor

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?

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 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?

Copy link
Member

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,
Copy link
Contributor

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?

@toofff
Copy link
Contributor Author

toofff commented Nov 11, 2017

Yes it will remove StyleCI integration after merging.
I forgot to do it yesterday, but can I add PHPCSFIxer in travis?
What do you think @core23 @greg0ire ?

@soullivaneuh
Copy link
Member

The project php-cs-fixer-styleci-bridge has not been released for several months.

Not released from month does not mean this one is not maintained at all. Otherwise, I would put a message about it. 😉

When you run php-cs-fix in version 2, nothing works.

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.

Copy link
Member

@soullivaneuh soullivaneuh left a 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
Copy link
Member

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.

Copy link
Member

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,
Copy link
Member

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',
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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,
Copy link
Member

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.

Copy link
Member

@soullivaneuh soullivaneuh left a 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,
Copy link
Member

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,
Copy link
Member

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);
Copy link
Member

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.

@soullivaneuh
Copy link
Member

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+?

@@ -42,8 +42,7 @@ public function getConfigTreeBuilder()
->arrayNode('packages')
->prototype('scalar')->end()
->end()
->end()
;
Copy link
Member

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/',
Copy link
Member

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.

Copy link
Member

@soullivaneuh soullivaneuh left a 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. 👍

Copy link
Member

@soullivaneuh soullivaneuh left a 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",
Copy link
Member

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?

'header' => $header,
'location' => 'after_open',
],
'no_extra_consecutive_blank_lines' => [
Copy link
Member

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.

return PhpCsFixer\Config::create()
->setFinder($finder)
->setRules([
'@Symfony' => true,
Copy link
Member

@soullivaneuh soullivaneuh Nov 13, 2017

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

@toofff
Copy link
Contributor Author

toofff commented Nov 14, 2017

@soullivaneuh I will take time at the lunch break to finalize the last comments.

Thank you for your help

@toofff
Copy link
Contributor Author

toofff commented Nov 14, 2017

@soullivaneuh I think I have corrected all your requests.

By cons I do not feel that it works the symbolic link for the file .php_cs.dist at the root of the project. Because it should have returned an error with the current configuration.
The only solution I find is to duplicate the .php_cs.dist file at the root of the project.

Do I need to do other PRs in other Sonata projects to remove dependency sllh/php-cs-fixer-styleci-bridge, for example the projet SonataAdminBundle ?

Copy link
Member

@soullivaneuh soullivaneuh left a 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.

@@ -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
Copy link
Member

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
Copy link
Member

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
Copy link
Member

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.

@toofff
Copy link
Contributor Author

toofff commented Nov 22, 2017

@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?
I also have to correct the errors that will be reported by PHP-Cs-Fixer after launching it with the new rules for PHP 7.1?
If it's good for you, I'm doing it now.

@soullivaneuh
Copy link
Member

@soullivaneuh If you do not mind, I'd really like to finish it myself.

No problem, just help proposing. 👍

For your comment #336, if I understand correctly, you want PHP 7.1 to be required?

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 also have to correct the errors that will be reported by PHP-Cs-Fixer after launching it with the new rules for 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.

Do I need to do other PRs in other Sonata projects to remove dependency sllh/php-cs-fixer-styleci-bridge, for example the projet SonataAdminBundle ?

If you want to do it, you can. But after getting this PR merged and deployed across repositories.

@toofff
Copy link
Contributor Author

toofff commented Nov 22, 2017

@soullivaneuh

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
Copy link

@dunglas dunglas Nov 23, 2017

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

@@ -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
Copy link

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'));
Copy link

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.

@dunglas
Copy link

dunglas commented Nov 23, 2017

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+).

@soullivaneuh
Copy link
Member

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
Copy link
Member

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",
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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) {
Copy link
Member

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
Copy link
Member

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:

git diff --exit-code
(BTW, you don't need the --dry-run and the --diff as we already check the diff at the end.

Sorry for that, I forgot to tell you.

@soullivaneuh
Copy link
Member

I'll continue and finish your PR in #358, we need it for user-bundle.

Thanks a lot for your work! 👍

@toofff
Copy link
Contributor Author

toofff commented Dec 4, 2017

@soullivaneuh

I did not have time to look at it this weekend.
I wanted to propose to you to finish it, so that it is easier for you.

Thanks and see you soon on an upcoming pull request ;)

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.

CS: php_unit_dedicate_assert fixer CS: modernize_types_casting fixer
5 participants