-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Fix coding standards #27852
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
Fix coding standards #27852
Conversation
@stof , would be great if you can create a benchmark without and with those changes ! |
I don't think a benchmark will show much differences here, as the hot path of the DI component (and of a few other places) were already fully-qualified manually by @nicolas-grekas (well, maybe not in 2.8, but at least in newer versions). |
Actually, the process for this is:
|
@nicolas-grekas the update of the config file (exclude rules) will be needed for newer branches too (due to renaming some code, or adding more places needing to be excluded). |
but yes, fixing conflicts would be done by running the command again. |
Wouldn't it make more sense to have |
@iltar this would require using And for classes, our existing rule is already to avoid use statements for global classes, so this is consistent. and regarding merge conflicts, this is precisely the reason why I'm doing this in 2.8, not in master (so that all branches are using the same CS), and why I'm doing it now and not 6 months ago (the change is now automated) |
I mention this because a lot of people are complaining about the readability of backslashes in the code, and are asking for imports instead. I do agree with them on this point, because it does hurt readability quite some. I understand we can't merge this in 2.8, but why not do it in 3.4+ only? 2.8 support won't last long anymore either way and to be fair, people should've already upgraded a while ago. |
@iltar 3.4 supports PHP 5.5.9+, so this would not be 3.4+, but 4.0+. And having CS violations in 4.x for any code contributed in 3.4 and merged up would mean that we suffer from branch merging for the whole 3.4 lifetime (i.e. for the next 2 years: https://symfony.com/roadmap/3.4). |
Ah my bad, I forgot that 3.4 was not on 7.x yet. Yay for LTS. |
regarding the constant invocation, I will revert the change, and disable the rule temporarily, until PHP-CS-Fixer/PHP-CS-Fixer#3876 is merged and released. This would avoid some of the existing changes which add visual clutter for no performance benefit. |
@stof Can you revert what needs to be reverted so that I can merge this one and then I will take care of propagating changes up to master? |
fabbot is now using v2.12.2 |
We don't want to run it on non-namespaced code to reduce visual clutter.
@fabpot done. The list of excluded files in the php-cs--fixer configuration file (updated in the first commit of this PR) will need some adjustments for newer branches (I have a branch locally with a similar commit for master (I started there before switching target branch), and there were a few differences. I intentionally kept multiple commits in the history, to better see the different changes performed in this PR (as some of them are automated). |
CliDumperTest.php needs a tweak: the last frame ( |
@@ -35,22 +35,22 @@ | |||
} | |||
|
|||
if (in_array(STDOUT, $w) && strlen($out) > 0) { | |||
$written = fwrite(STDOUT, (binary) $out, 32768); | |||
$written = fwrite(STDOUT, (string) $out, 32768); |
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.
wow, I did not expect to see binary casting so much in real code :D
Thank you @stof. |
This PR was squashed before being merged into the 2.8 branch (closes #27852). Discussion ---------- Fix coding standards | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a This PR is mostly about running the PHP-CS-Fixer (v2.12.1) in the whole codebase. - I updated the exclude rule to avoid some false positives for the `error_suppression` fixer (we have more files triggering unsilenced deprecations on purpose than when building the initial whitelist, mostly). - I ran the fixer with this updated config. Most changes were related to fully-qualifying some constants, with the new fixer implemented in PHP-CS-Fixer/PHP-CS-Fixer#3127, for which @nicolas-grekas and I suggested a config to include in the Symfony ruleset. Based on the output, I suggested a feature request in PHP-CS-Fixer/PHP-CS-Fixer#3872 as we might want to avoid the `\` in non-namespaced files to improve readability. We might want to remove the second commit of this PR if we decide to wait for the feature to be implemented (update: implementation is contributed in PHP-CS-Fixer/PHP-CS-Fixer#3876) - I added the `native_function_invocation` fixer explicitly, to automatically fully-qualify calls to compiler-optimized functions. This feature was implemented in PHP-CS-Fixer based on our feature request (as currently, we do such thing only manually in some hot path, because it could not be automated). I opened PHP-CS-Fixer/PHP-CS-Fixer#3873 to include it in the ruleset automatically. TODOs: - [x] agree on the updated rules - [x] update fabbot to use the new version of PHP-CS-Fixer - [ ] make separate PRs for newer branches with their own updates (exclude rules, and CS fixes), once this PR gets merged. Commits ------- 538c69d Fix Clidumper tests 04654cf Enable the fixer enforcing fully-qualified calls for compiler-optimized functions f00b327 Apply fixers 720ed4d Disable the native_constant_invocation fixer until it can be scoped 8892b98 Update the list of excluded files for the CS fixer
Now merged up to master. |
nice to see the new fixers being used :D thanks all! |
This PR is mostly about running the PHP-CS-Fixer (v2.12.1) in the whole codebase.
error_suppression
fixer (we have more files triggering unsilenced deprecations on purpose than when building the initial whitelist, mostly).\
in non-namespaced files to improve readability. We might want to remove the second commit of this PR if we decide to wait for the feature to be implemented (update: implementation is contributed in NativeConstantInvocationFixer - add the scope option PHP-CS-Fixer/PHP-CS-Fixer#3876)native_function_invocation
fixer explicitly, to automatically fully-qualify calls to compiler-optimized functions. This feature was implemented in PHP-CS-Fixer based on our feature request (as currently, we do such thing only manually in some hot path, because it could not be automated). I opened Add the native_function_invocation fixer in the Symfony:risky ruleset PHP-CS-Fixer/PHP-CS-Fixer#3873 to include it in the ruleset automatically.TODOs: