-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Reference assignment operator =& gets broken up #7303
Comments
It's a bit of a tricky question. I guess the expected formatting of reference assignment is something that PER may want to clarify. I think there is a problem on the PHP-CS-Fixer side either way though, as it should produce one of |
Thank you for the explanation 🙂. We probably need to make sure that it is just left as-is, regardless if it's |
Yeah, I think that would be the ideal thing to do. |
@Wirone Would you see the |
@greew what about universal |
That might actually be better, yeah! And also allow for only handling e.g. assignments, if only that is the desired case. I might give it a try, but since it's my first time working with PHP-CS-Fixer core, the PR will probably need some work and comments! ;) |
I am not convinced it's good idea @Wirone . We do not want to create a dedicated rule for each symbol, like If we have a rule that handle unary operators well, but it handles one extra case too much ( I'm not sure about |
if we would go with
but we miss the yep, PHP docs also use this styling |
Actually, PHP uses both types: ref https://www.php.net/manual/en/language.references.whatdo.php#language.references.whatdo.assign |
@keradus I wasn't aware that |
I have just tested using |
The PSR-12 documentation only makes two explicit remarks about unary operators. So anything else shouldn't be 'fixed' when using the PSR-12 ruleset.
https://www.php-fig.org/psr/psr-12/#61-unary-operators .With the new forced (and non-configurable) --- if (! $someBoolean) {
+++ if (!$someBoolean) {
https://www.php.net/manual/en/language.operators.logical.php |
logical operators can be unary (eg also from PHP docs: https://www.php.net/manual/en/language.operators.php
with that, PSR 12 saying to have no space for unary operator, making no space when using If you prefer to follow limited set of PSR set, you can adjust your project config to disable that rule. |
Good point 👍 I've scratched that argument from my original comment.
Ah, but the fact is that it doesn't say that. It only cites two specific rules in the section 'unary operators' without mentioning a general rule applying to all unary operators. |
This is a change for me, but PHP-CS-Fixer/PHP-CS-Fixer#7303 makes a good point for `if (!defined())` being a better match with PSR-12 than `if(! defined())`.
Bug report
Description
The binary_operator_spaces fixer using at_least_single_space (part of PSR12 ruleset since recently) will break up the reference assignment operator
=&
by inserting a space between the two parts:I think this should either be left as
$a =& $b
(preferred) or become$a = &$b
(misleading), but the chosen form of$a = & $b
is not a style I have ever seen.Runtime version
PHP CS Fixer 3.26.1 Crank Cake by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.2-1ubuntu2.14
Command
The text was updated successfully, but these errors were encountered: