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

Issue:
version 3.6.0 class_reference_name_casing will lowercase the constant
## Bug report

PHP CS Fixer version: v3.6.0 Roe Deer
PHP version: 8.1.2
PHP ext: swoole

It works well in version 3.5, but when update to 3.6.0 it breaks my code.
because of the config `'class_reference_name_casing' => true` in the ruleset `@PhpCsFixer`

```php
<?php

declare(strict_types=1);

return [
    - 'mode' => SWOOLE_PROCESS,
    + 'mode' => swoole_process,
];
```

( `SWOOLE_PROCESS` is a constant defined by php swoole extentsion )

I dont know why it will change `SWOOLE_PROCESS` to `swoole_process`





Discussion:
Thanks fro reporting :+1: ,
a fix has been merged for it and will ship in the release



Patch:
diff --git a/src/AbstractNoUselessElseFixer.php b/src/AbstractNoUselessElseFixer.php
index ea38102027c..96f6bb09f65 100644
--- a/src/AbstractNoUselessElseFixer.php
+++ b/src/AbstractNoUselessElseFixer.php
@@ -68,7 +68,7 @@ protected function isSuperfluousElse(Tokens $tokens, int $index): bool
                 return false;
             }
 
-            if ($tokens[$candidateIndex]->equals([T_THROW])) {
+            if ($tokens[$candidateIndex]->isGivenKind(T_THROW)) {
                 $previousIndex = $tokens->getPrevMeaningfulToken($candidateIndex);
 
                 if (!$tokens[$previousIndex]->equalsAny([';', '{'])) {
diff --git a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php
index 6d1206bcbd1..3bf8dfd3cd2 100644
--- a/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php
+++ b/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php
@@ -121,7 +121,7 @@ private function fixSpacing(int $index, Tokens $tokens): void
 
             if (
                 $currentToken->equals(',') && !$tokens[$prevIndex]->isComment()
-                && (true === $this->configuration['after_heredoc'] || !$tokens[$prevIndex]->equals([T_END_HEREDOC]))
+                && (true === $this->configuration['after_heredoc'] || !$tokens[$prevIndex]->isGivenKind(T_END_HEREDOC))
             ) {
                 $tokens->removeLeadingWhitespace($i);
             }
diff --git a/src/Fixer/Casing/ClassReferenceNameCasingFixer.php b/src/Fixer/Casing/ClassReferenceNameCasingFixer.php
index f17f2ba8c8c..11b70ac41a3 100644
--- a/src/Fixer/Casing/ClassReferenceNameCasingFixer.php
+++ b/src/Fixer/Casing/ClassReferenceNameCasingFixer.php
@@ -78,6 +78,7 @@ private function getClassReference(Tokens $tokens, NamespaceAnalysis $namespace)
                 T_CASE, // PHP 8.1 trait enum-case
                 T_CLASS,
                 T_CONST,
+                T_DOUBLE_ARROW,
                 T_DOUBLE_COLON,
                 T_FUNCTION,
                 T_INTERFACE,
@@ -120,7 +121,7 @@ private function getClassReference(Tokens $tokens, NamespaceAnalysis $namespace)
                 continue;
             }
 
-            if (!$tokens[$prevIndex]->isGivenKind([T_NEW]) && $tokens[$nextIndex]->equals('(')) {
+            if (!$tokens[$prevIndex]->isGivenKind(T_NEW) && $tokens[$nextIndex]->equals('(')) {
                 continue;
             }
 
diff --git a/src/Fixer/ControlStructure/NoBreakCommentFixer.php b/src/Fixer/ControlStructure/NoBreakCommentFixer.php
index 2a29fa25d52..dfcb208804f 100644
--- a/src/Fixer/ControlStructure/NoBreakCommentFixer.php
+++ b/src/Fixer/ControlStructure/NoBreakCommentFixer.php
@@ -154,7 +154,7 @@ private function fixCase(Tokens $tokens, int $casePosition): void
                 continue;
             }
 
-            if ($tokens[$i]->isGivenKind([T_THROW])) {
+            if ($tokens[$i]->isGivenKind(T_THROW)) {
                 $previousIndex = $tokens->getPrevMeaningfulToken($i);
 
                 if ($previousIndex === $casePosition || $tokens[$previousIndex]->equalsAny(['{', ';', '}', [T_OPEN_TAG]])) {
diff --git a/src/Fixer/Import/SingleImportPerStatementFixer.php b/src/Fixer/Import/SingleImportPerStatementFixer.php
index 684a4ae8370..ce4aa66cf50 100644
--- a/src/Fixer/Import/SingleImportPerStatementFixer.php
+++ b/src/Fixer/Import/SingleImportPerStatementFixer.php
@@ -130,7 +130,7 @@ private function getGroupStatements(Tokens $tokens, string $groupPrefix, int $gr
         for ($i = $groupOpenIndex + 1; $i <= $groupCloseIndex; ++$i) {
             $token = $tokens[$i];
 
-            if ($token->equals(',') && $tokens[$tokens->getNextMeaningfulToken($i)]->equals([CT::T_GROUP_IMPORT_BRACE_CLOSE])) {
+            if ($token->equals(',') && $tokens[$tokens->getNextMeaningfulToken($i)]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_CLOSE)) {
                 continue;
             }
 
diff --git a/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php b/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php
index 271b1a60c20..e8365c4b23f 100644
--- a/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php
+++ b/src/Fixer/PhpUnit/PhpUnitDedicateAssertInternalTypeFixer.php
@@ -169,7 +169,7 @@ protected function applyPhpUnitClassFix(Tokens $tokens, int $startIndex, int $en
             $expectedTypeTokenIndex = $tokens->getNextMeaningfulToken($bracketTokenIndex);
             $expectedTypeToken = $tokens[$expectedTypeTokenIndex];
 
-            if (!$expectedTypeToken->equals([T_CONSTANT_ENCAPSED_STRING])) {
+            if (!$expectedTypeToken->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) {
                 continue;
             }
 
diff --git a/src/Tokenizer/AbstractTypeTransformer.php b/src/Tokenizer/AbstractTypeTransformer.php
index 9e938189a16..53fa51355f6 100644
--- a/src/Tokenizer/AbstractTypeTransformer.php
+++ b/src/Tokenizer/AbstractTypeTransformer.php
@@ -56,7 +56,7 @@ protected function doProcess(Tokens $tokens, int $index, $originalToken): void
 
         $prevPrevTokenIndex = $tokens->getPrevMeaningfulToken($prevIndex);
 
-        if ($tokens[$prevPrevTokenIndex]->isGivenKind([T_CATCH])) {
+        if ($tokens[$prevPrevTokenIndex]->isGivenKind(T_CATCH)) {
             $this->replaceToken($tokens, $index);
 
             return;
diff --git a/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php b/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php
index 00be8d743f5..2736c83c259 100644
--- a/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php
+++ b/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php
@@ -51,7 +51,7 @@ public function getRequiredPhpVersionId(): int
      */
     public function process(Tokens $tokens, Token $token, int $index): void
     {
-        if (!$tokens[$index]->equals('(') || !$tokens[$tokens->getNextMeaningfulToken($index)]->equals([T_NEW])) {
+        if (!$tokens[$index]->equals('(') || !$tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(T_NEW)) {
             return;
         }
 


Test patch:
diff --git a/tests/Fixer/Casing/ClassReferenceNameCasingFixerTest.php b/tests/Fixer/Casing/ClassReferenceNameCasingFixerTest.php
index f1da8b11725..9a213c691e0 100644
--- a/tests/Fixer/Casing/ClassReferenceNameCasingFixerTest.php
+++ b/tests/Fixer/Casing/ClassReferenceNameCasingFixerTest.php
@@ -137,6 +137,10 @@ public function provideFixCases(): \Generator
             '<?php class Foo { use exception; }',
         ];
 
+        yield [
+            '<?php $foo = ["const" => exception];',
+        ];
+
         yield [
             '<?php
 namespace {
@@ -181,6 +185,23 @@ public function provideFixCases(): \Generator
             '<?php try { foo(); } catch(\LogicException $e) {}',
             '<?php try { foo(); } catch(\logicexception $e) {}',
         ];
+
+        yield [
+            '<?php
+                Closure::bind(fn () => null, null, new class {});
+                \Closure::bind(fn () => null, null, new class {});
+
+                Foo\Bar::bind(fn () => null, null, new class {});
+                \A\B\\Bar::bind(fn () => null, null, new class {});
+            ',
+            '<?php
+                CLOSURE::bind(fn () => null, null, new class {});
+                \CLOSURE::bind(fn () => null, null, new class {});
+
+                Foo\Bar::bind(fn () => null, null, new class {});
+                \A\B\\Bar::bind(fn () => null, null, new class {});
+            ',
+        ];
     }
 
     /**