Browse Source

OrderedClassElementsFixer - fix

SpacePossum 5 years ago
parent
commit
6c543dbfac

+ 1 - 1
src/Fixer/ClassNotation/OrderedClassElementsFixer.php

@@ -333,7 +333,7 @@ class Example
 
                 if ('property' === $element['type']) {
                     $element['name'] = $tokens[$i]->getContent();
-                } elseif (\in_array($element['type'], ['use_trait', 'constant', 'method', 'magic'], true)) {
+                } elseif (\in_array($element['type'], ['use_trait', 'constant', 'method', 'magic', 'construct', 'destruct'], true)) {
                     $element['name'] = $tokens[$tokens->getNextMeaningfulToken($i)]->getContent();
                 }
 

+ 30 - 0
tests/Fixer/ClassNotation/OrderedClassElementsFixerTest.php

@@ -888,4 +888,34 @@ EOT
 
         $this->fixer->configure(['order' => ['foo']]);
     }
+
+    /**
+     * @param string $methodName1
+     * @param string $methodName2
+     *
+     * @dataProvider provideWithConfigWithNoCandidateCases
+     */
+    public function testWithConfigWithNoCandidate($methodName1, $methodName2)
+    {
+        $template = '<?php
+class TestClass
+{
+    public function %s(){}
+    public function %s(){}
+}';
+        $this->fixer->configure(['order' => ['use_trait'], 'sortAlgorithm' => 'alpha']);
+
+        $this->doTest(
+            sprintf($template, $methodName2, $methodName1),
+            sprintf($template, $methodName1, $methodName2)
+        );
+    }
+
+    public function provideWithConfigWithNoCandidateCases()
+    {
+        yield ['z', '__construct'];
+        yield ['z', '__destruct'];
+        yield ['z', '__sleep'];
+        yield ['z', 'abc'];
+    }
 }

+ 27 - 2
tests/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixerTest.php

@@ -336,9 +336,9 @@ final class PhpdocAddMissingParamAnnotationFixerTest extends AbstractFixerTestCa
      * @dataProvider provideFix71Cases
      * @requires PHP 7.1
      */
-    public function testFix71($expected, $input = null, array $config = [])
+    public function testFix71($expected, $input, array $config)
     {
-        $this->fixer->configure($config ?: ['only_untyped' => false]);
+        $this->fixer->configure($config);
 
         $this->doTest($expected, $input);
     }
@@ -358,6 +358,31 @@ final class PhpdocAddMissingParamAnnotationFixerTest extends AbstractFixerTestCa
      * @param int $bar
      */
     function p1(?array $foo = null, $bar) {}',
+                ['only_untyped' => false],
+            ],
+            [
+                '<?php
+    /**
+     * Foo
+     * @param mixed $bar
+     */
+    function p1(?int $foo = 0, $bar) {}',
+                '<?php
+    /**
+     * Foo
+     */
+    function p1(?int $foo = 0, $bar) {}',
+                ['only_untyped' => true],
+            ],
+            [
+                '<?php
+    /**
+     * Foo
+     * @return int
+     */
+    function p1(?int $foo = 0) {}',
+                null,
+                ['only_untyped' => true],
             ],
         ];
     }