Repository: FriendsOfPHP/PHP-CS-Fixer (php)

Issue:
yoda_style fixer does not work with named arguments in PHP 8
**Summary**

* `yoda_style` fixer does not appear to be aware of named arguments:
* PHP CS Fixer 3.1.0 River by Fabien Potencier and Dariusz Ruminski
* Runtime: PHP 8.0.10

**Code snippet**

```php
<?php

new Foo(
    bar: $var === 'value'
);
```

**Applied filters**

yoda_style, single_blank_line_at_eof

**Expected fix**

```bar: 'value' === $var```

**Actual fix**

```'value' === bar: $var```

Note: when using parenthesis around the comparison, the fixer works as expected, producing ```bar: ('value' === $var)```

**Command & Output**

```
% ./vendor/bin/php-cs-fixer fix --diff --dry-run test.php -vvv
PHP CS Fixer 3.1.0 River by Fabien Potencier and Dariusz Ruminski
Runtime: PHP 8.0.10
Loaded config default from ".php-cs-fixer.dist.php".
Using cache file ".php-cs-fixer.cache".
Paths from configuration file have been overridden by paths provided as command arguments.
E                                                                                                                                                                                                                                                  1 / 1 (100%)
Legend: ?-unknown, I-invalid file syntax (file ignored), S-skipped (cached or empty file), .-no changes, F-fixed, E-error

Checked all files in 0.011 seconds, 20.000 MB memory used

Files that were not fixed due to errors reported during linting after fixing:
   1) test.php

                                                                                    
        [PhpCsFixer\Linter\LintingException]                                        
        Parse error: syntax error, unexpected token ":", expecting ")" on line 14.  
                                                                                    

      Applied fixers: yoda_style, single_blank_line_at_eof
      ---------- begin diff ----------
--- test.php
+++ test.php
@@ -1,6 +1,15 @@
 <?php
 
 new Foo(
-    bar: $var === 'value'
+    'value' === bar: $var
 );
```

**Config file**

```php
<?php

$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude('var')
    ->notPath('config/bundles.php')
;

$config = new PhpCsFixer\Config();

$config
    ->setRiskyAllowed(false)
    ->setRules([
        '@Symfony' => true,
        '@PhpCsFixer' => true,
        'php_unit_test_class_requires_covers' => false,
        'php_unit_internal_class' => false,
        '@DoctrineAnnotation' => true,
        'list_syntax' => ['syntax' => 'long'],
        'array_syntax' => ['syntax' => 'short'],
        'no_unused_imports' => true,
    ])
    ->setFinder($finder)
;

return $config;
```

---

Great work, awesome tools. Thanks for all your hard work.

Pull request description:
YodaStyleFixer - PHP8 named arguments support
close #5979 

Patch:
diff --git a/src/Fixer/ControlStructure/YodaStyleFixer.php b/src/Fixer/ControlStructure/YodaStyleFixer.php
index da4ed5109..8cf4eba86 100644
--- a/src/Fixer/ControlStructure/YodaStyleFixer.php
+++ b/src/Fixer/ControlStructure/YodaStyleFixer.php
@@ -239,6 +239,10 @@ private function findComparisonStart(Tokens $tokens, int $index): int
                 continue;
             }
 
+            if ($token->isGivenKind([CT::T_NAMED_ARGUMENT_COLON])) {
+                break;
+            }
+
             if ($this->isOfLowerPrecedence($token)) {
                 break;
             }


Test patch:
diff --git a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php
index c77d59cb8..a44a163ff 100644
--- a/tests/Fixer/ControlStructure/YodaStyleFixerTest.php
+++ b/tests/Fixer/ControlStructure/YodaStyleFixerTest.php
@@ -1050,6 +1050,11 @@ public function provideFix80Cases(): \Generator
             null,
             ['equal' => true, 'identical' => true],
         ];
+
+        yield [
+            '<?php new Foo(bar: 1 === $var);',
+            '<?php new Foo(bar: $var === 1);',
+        ];
     }
 
     /**