Browse Source

Merge branch '2.17' into 2.18

Dariusz Ruminski 4 years ago
parent
commit
41b246c19d

+ 1 - 1
.github/workflows/ci.yml

@@ -143,7 +143,7 @@ jobs:
         env:
         env:
           PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
           PHP_CS_FIXER_IGNORE_ENV: ${{ matrix.PHP_CS_FIXER_IGNORE_ENV }}
           PHP_CS_FIXER_FUTURE_MODE: 1
           PHP_CS_FIXER_FUTURE_MODE: 1
-        run: php php-cs-fixer --diff --dry-run -v fix
+        run: php php-cs-fixer fix --diff --dry-run -v
 
 
       - name: Execute deployment checks
       - name: Execute deployment checks
         if: matrix.execute-deployment == 'yes'
         if: matrix.execute-deployment == 'yes'

+ 7 - 0
src/Tokenizer/Analyzer/CommentsAnalyzer.php

@@ -84,6 +84,13 @@ final class CommentsAnalyzer
         $nextIndex = $index;
         $nextIndex = $index;
         do {
         do {
             $nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
             $nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
+
+            if (\defined('T_ATTRIBUTE')) {
+                while (null !== $nextIndex && $tokens[$nextIndex]->isGivenKind(T_ATTRIBUTE)) {
+                    $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ATTRIBUTE, $nextIndex);
+                    $nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
+                }
+            }
         } while (null !== $nextIndex && $tokens[$nextIndex]->equals('('));
         } while (null !== $nextIndex && $tokens[$nextIndex]->equals('('));
 
 
         if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
         if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {

+ 68 - 0
tests/Fixer/Phpdoc/PhpdocToCommentFixerTest.php

@@ -713,4 +713,72 @@ $first = true;// needed because by default first docblock is never fixed.
             ],
             ],
         ];
         ];
     }
     }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFix80Cases
+     * @requires PHP 8.0
+     */
+    public function testFix80($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFix80Cases()
+    {
+        return [
+            [
+                '<?php
+/**
+ * @Annotation
+ */
+#[CustomAnnotationA]
+Class MyAnnotation3
+{
+    /**
+     * @Annotation
+     */
+    #[CustomAnnotationB]
+    #[CustomAnnotationC]
+    public function foo() {}
+
+    /**
+     * @Annotation
+     */
+    #[CustomAnnotationD]
+    public $var;
+
+    /*
+     * end of class
+     */
+}',
+                '<?php
+/**
+ * @Annotation
+ */
+#[CustomAnnotationA]
+Class MyAnnotation3
+{
+    /**
+     * @Annotation
+     */
+    #[CustomAnnotationB]
+    #[CustomAnnotationC]
+    public function foo() {}
+
+    /**
+     * @Annotation
+     */
+    #[CustomAnnotationD]
+    public $var;
+
+    /**
+     * end of class
+     */
+}',
+            ],
+        ];
+    }
 }
 }

+ 1 - 0
tests/Smoke/CiIntegrationTest.php

@@ -141,6 +141,7 @@ final class CiIntegrationTest extends AbstractSmokeTest
         ]);
         ]);
 
 
         $optionalIncompatibilityWarning = 'PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.
         $optionalIncompatibilityWarning = 'PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.4.*.
+Current PHP version: '.PHP_VERSION.'.
 Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.
 Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.
 ';
 ';
 
 

+ 27 - 0
tests/Tokenizer/Analyzer/CommentsAnalyzerTest.php

@@ -340,4 +340,31 @@ $bar;',
             ['<?php /* Before anonymous function */ $fn = fn($x) => $x + 1;'],
             ['<?php /* Before anonymous function */ $fn = fn($x) => $x + 1;'],
         ];
         ];
     }
     }
+
+    /**
+     * @param string $code
+     *
+     * @dataProvider providePhpdocCandidatePhp80Cases
+     * @requires PHP 8.0
+     */
+    public function testPhpdocCandidatePhp80($code)
+    {
+        $tokens = Tokens::fromCode($code);
+        $index = $tokens->getNextTokenOfKind(0, [[T_COMMENT], [T_DOC_COMMENT]]);
+        $analyzer = new CommentsAnalyzer();
+
+        static::assertTrue($analyzer->isBeforeStructuralElement($tokens, $index));
+    }
+
+    public function providePhpdocCandidatePhp80Cases()
+    {
+        return [
+            ['<?php
+/**
+ * @Annotation
+ */
+#[CustomAnnotationA]
+Class MyAnnotation3 {}'],
+        ];
+    }
 }
 }