Browse Source

bug: Fix priority between `modernize_types_casting` and `no_unneeded_control_parentheses` (#6687)

Julien Falque 2 years ago
parent
commit
9c7070b127

+ 10 - 0
src/Fixer/CastNotation/ModernizeTypesCastingFixer.php

@@ -50,6 +50,16 @@ final class ModernizeTypesCastingFixer extends AbstractFunctionReferenceFixer
         );
     }
 
+    /**
+     * {@inheritdoc}
+     *
+     * Must run before NoUnneededControlParenthesesFixer.
+     */
+    public function getPriority(): int
+    {
+        return 31;
+    }
+
     /**
      * {@inheritdoc}
      */

+ 1 - 1
src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php

@@ -163,7 +163,7 @@ while ($y) { continue (2); }
      * {@inheritdoc}
      *
      * Must run before ConcatSpaceFixer, NoTrailingWhitespaceFixer.
-     * Must run after NoAlternativeSyntaxFixer.
+     * Must run after ModernizeTypesCastingFixer, NoAlternativeSyntaxFixer.
      */
     public function getPriority(): int
     {

+ 3 - 0
tests/AutoReview/FixerFactoryTest.php

@@ -492,6 +492,9 @@ final class FixerFactoryTest extends TestCase
                 'php_unit_dedicate_assert',
                 'single_space_after_construct',
             ],
+            'modernize_types_casting' => [
+                'no_unneeded_control_parentheses',
+            ],
             'multiline_whitespace_before_semicolons' => [
                 'space_after_semicolon',
             ],

+ 13 - 0
tests/Fixtures/Integration/priority/modernize_types_casting,no_unneeded_control_parentheses.test

@@ -0,0 +1,13 @@
+--TEST--
+Integration of fixers: modernize_types_casting,no_unneeded_control_parentheses.
+--RULESET--
+{"modernize_types_casting": true, "no_unneeded_control_parentheses": {"statements": ["others"]}}
+--EXPECT--
+<?php
+
+$foo = (int) foo();
+
+--INPUT--
+<?php
+
+$foo = intval(foo());