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

Issue:
Lowercase native constants in @var tag
## Bug report

### Description

Fixer fixes array field names with same name as native constants in @var tag.

### Runtime version

PHP CS Fixer 3.14.2 Oliva
PHP runtime: 8.1.13

### Code snippet that reproduces the problem

```php
/** @var array<int, array{Field: string, Type: string, Null: string, Extra: string}> $tableDescribe */
$tableDescribe = $conn->fetchAllAssociative('describe '.$tableName);
  ```

becomes

```php
/** @var array<int, array{Field: string, Type: string, null: string, Extra: string}> $tableDescribe */
$tableDescribe = $conn->fetchAllAssociative('describe '.$tableName);
  ```


Discussion:

Patch:
diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php
index b447d1e3ea0..ab39f1089e6 100644
--- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php
+++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php
@@ -83,7 +83,7 @@ public function configure(array $configuration): void
         }, $this->configuration['groups']));
 
         $this->patternToFix = sprintf(
-            '/(?<![a-zA-Z0-9_\x80-\xff]\\\\)(\b|.(?=\$))(%s)\b(?!\\\\)/i',
+            '/(?<![a-zA-Z0-9_\x80-\xff]\\\\)(\b|.(?=\$))(%s)\b(?!(\\\\|:))/i',
             implode(
                 '|',
                 array_map(


Test patch:
diff --git a/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php b/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php
index d928d368188..4e18de3bcb8 100644
--- a/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php
+++ b/tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php
@@ -30,138 +30,114 @@ final class PhpdocTypesFixerTest extends AbstractFixerTestCase
 {
     /**
      * @dataProvider provideFixCases
+     *
+     * @param array<string, mixed> $configuration
      */
-    public function testFix(string $expected, ?string $input = null): void
+    public function testFix(string $expected, ?string $input = null, array $configuration = []): void
     {
+        $this->fixer->configure($configuration);
+
         $this->doTest($expected, $input);
     }
 
-    public function testWindowsLinebreaks(): void
+    public static function provideFixCases(): iterable
     {
-        $this->doTest(
+        yield 'windows line breaks' => [
             "<?php /**\r\n * @param string|string[] \$bar\r\n *\r\n * @return int[]\r\n */\r\n",
-            "<?php /**\r\n * @param STRING|String[] \$bar\r\n *\r\n * @return inT[]\r\n */\r\n"
-        );
-    }
+            "<?php /**\r\n * @param STRING|String[] \$bar\r\n *\r\n * @return inT[]\r\n */\r\n",
+        ];
 
-    public function testConversion(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'conversion' => [
+            '<?php
     /**
      * @param boolean|array|Foo $bar
      *
      * @return int|float
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @param Boolean|Array|Foo $bar
      *
      * @return inT|Float
      */
 
-EOF;
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testArrayStuff(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'array stuff' => [
+            '<?php
     /**
      * @param string|string[] $bar
      *
      * @return int[]
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @param STRING|String[] $bar
      *
      * @return inT[]
      */
 
-EOF;
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testNestedArrayStuff(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'nested array stuff' => [
+            '<?php
     /**
      * @return int[][][]
      */
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @return INT[][][]
      */
-EOF;
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testMixedAndVoid(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'mixed and void' => [
+            '<?php
     /**
      * @param mixed $foo
      *
      * @return void
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @param Mixed $foo
      *
      * @return Void
      */
 
-EOF;
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testIterableFix(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'iterable' => [
+            '<?php
     /**
      * @param iterable $foo
      *
      * @return Itter
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @param Iterable $foo
      *
      * @return Itter
      */
 
-EOF;
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testMethodAndPropertyFix(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'method and property' => [
+            '<?php
 /**
  * @method self foo()
  * @property int $foo
@@ -169,10 +145,8 @@ public function testMethodAndPropertyFix(): void
  * @property-write mixed $baz
  */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
 /**
  * @method Self foo()
  * @property Int $foo
@@ -180,36 +154,26 @@ public function testMethodAndPropertyFix(): void
  * @property-write MIXED $baz
  */
 
-EOF;
-
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testThrows(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'throws' => [
+            '<?php
 /**
  * @throws static
  */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
 /**
  * @throws STATIC
  */
 
-EOF;
-
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testInlineDoc(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'inline doc' => [
+            '<?php
     /**
      * Does stuff with stuffs.
      *
@@ -219,10 +183,8 @@ public function testInlineDoc(): void
      * }
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * Does stuff with stuffs.
      *
@@ -232,41 +194,30 @@ public function testInlineDoc(): void
      * }
      */
 
-EOF;
-
-        $this->doTest($expected, $input);
-    }
+',
+        ];
 
-    public function testWithConfig(): void
-    {
-        $expected = <<<'EOF'
-<?php
+        yield 'with config' => [
+            '<?php
     /**
      * @param self|array|Foo $bar
      *
      * @return int|float|callback
      */
 
-EOF;
-
-        $input = <<<'EOF'
-<?php
+',
+            '<?php
     /**
      * @param SELF|Array|Foo $bar
      *
      * @return inT|Float|callback
      */
 
-EOF;
-
-        $this->fixer->configure(['groups' => ['simple', 'meta']]);
-        $this->doTest($expected, $input);
-    }
+',
+            ['groups' => ['simple', 'meta']],
+        ];
 
-    public function testGenerics(): void
-    {
-        $this->fixer->configure(['groups' => ['simple', 'meta']]);
-        $this->doTest(
+        yield 'generics' => [
             '<?php
             /**
              * @param array<int, object> $a
@@ -288,12 +239,10 @@ public function testGenerics(): void
              * @param iterable<BOOLBOOLBOOL|INTINTINT|ARRAY_BOOL_INT_STRING_> $thisShouldNotBeChangedNeither
              *
              * @return ARRAY<INT, ARRAY<STRING, ARRAY<INT, DoNotChangeThisAsThisIsAClass>>>
-             */'
-        );
-    }
+             */',
+            ['groups' => ['simple', 'meta']],
+        ];
 
-    public static function provideFixCases(): iterable
-    {
         yield 'callable' => [
             '<?php /**
                     * @param callable() $a
@@ -306,6 +255,15 @@ public static function provideFixCases(): iterable
                     * @param CALLABLE(BOOL, INT, STRING): FLOAT $c
                     */',
         ];
+
+        yield 'array shape with key name being also type name' => [
+            '<?php /**
+                    * @return array{FOO: bool, NULL: null|int, BAR: string|BAZ}
+                    */',
+            '<?php /**
+                    * @return array{FOO: BOOL, NULL: NULL|INT, BAR: STRING|BAZ}
+                    */',
+        ];
     }
 
     public function testWrongConfig(): void