Make the CS stricter; fix some bugs / issues#1007
Conversation
| 'after' => [ | ||
| [ | ||
| 'dummyDate' => true, | ||
| 'dummyDate' => null, |
There was a problem hiding this comment.
Because this is $nullManagement, which can only be string or null, not bool.
| 'ordered_imports' => true, | ||
| // 'phpdoc_add_missing_param_annotation' => [ | ||
| // 'only_untyped' => false, | ||
| // ], |
There was a problem hiding this comment.
I plan to get these in next... 😄
There was a problem hiding this comment.
@dunglas I want to get this in too... But this is gonna require quite a bit of manual work. 😆
4941c42 to
9d18991
Compare
| 'modernize_types_casting' => true, | ||
| // 'native_function_invocation' => true, | ||
| 'no_extra_consecutive_blank_lines' => [ | ||
| 'break', |
There was a problem hiding this comment.
This one may be a bit controversial, but I think it's good that it encourages us to not have complex logic nested inside a switch-case, or even avoid switch-case altogether.
There was a problem hiding this comment.
I agree with the intent, but it makes the code (even simple statements) less readable (IMO).
There was a problem hiding this comment.
Yeah, personally I prefer the blank line too, but for the sake of consistency...
There was a problem hiding this comment.
We cannot enforce a blank line before/after break;, but we can enforce break; always sticking to the next case:
switch ($str) {
case 'A':
$this->doSomething();
$this->doSomethingElse();
break;
case 'B':
$this->doSomethingAwesome();
break;
}There was a problem hiding this comment.
But we can ignore this rule too and check it manually (it's not a big deal after all).
There was a problem hiding this comment.
Do you need me to revert this? I'll have to do it manually...
There was a problem hiding this comment.
Don't worry about that, keep it as is.
| $methods = $route->getMethods(); | ||
|
|
||
| if ($resourceClass === $currentResourceClass && null !== $operation && (empty($methods) || in_array('GET', $methods))) { | ||
| if ($resourceClass === $currentResourceClass && null !== $operation && (empty($methods) || in_array('GET', $methods, true))) { |
There was a problem hiding this comment.
The call to empty can be replaced by the ! operator.
There was a problem hiding this comment.
I really don't like such implicit conversions... And I don't like empty too...
My preference would be 0 === count($methods), but I understand there is a performance overhead (how much?) for the function call.
There was a problem hiding this comment.
I prefer to keep in sync with what we do in Symfony (we remove empty, count and so on).
|
Awesome. Can you just fix StyleCI ? Putting the |
No. StyleCI is buggy here. See PHP-CS-Fixer/PHP-CS-Fixer#2590 Also, declare should go after file-level docblock, according to PSR-12 draft. |
|
So what do we do in the meantime? Disable StyleCI? Or disable the header check? |
|
Disabling the header check sounds reasonable. But it might escape our watchful eyes. 😄 |
|
We'll restore the check when PHP CS Fixer will be updated. |
|
StyleCI config updated. Can you rebase? |
9d18991 to
b4b3cc4
Compare
| ], | ||
| 'declare_strict_types' => true, | ||
| 'modernize_types_casting' => true, | ||
| // 'native_function_invocation' => true, |
There was a problem hiding this comment.
What do you guys think about this? I remember @dunglas talking about this before... We'll need to do Blackfire profiling for this to see the performance difference.
b4b3cc4 to
b80f208
Compare
|
Rebased. But StyleCI still has a problem with |
|
It could make sense for us to disable StyleCI (at least for now?), because frankly I don't see what's the added value of having it. |
|
Are you sure Symfony has changed this CS? |
|
Anyway StyleCI is useless since we run our own PHP CS Fixer instance. I've just disabled it. Can you rebase again? |
|
Styleci would make sense if it prevented the other CI from running on failure. |
|
Yes, since symfony/symfony-docs#6614
|
|
The only merit I see for StyleCI is the nice output, and the ability to send a PR. 😆 |
b80f208 to
766d106
Compare
|
Thank you @teohhanhui |
Stricter CS = better code, especially
declare(strict_types=1);