Browse Source

Merge branch 'master' into 3.0

* master:
  - Detect compile errors correctly - Fixed invalid syntax of test cases
  Fix PHP8 RuleSet inherit
  Remove accidentally inserted newlines

# Conflicts:
#	tests/Fixer/Casing/LowercaseConstantsFixerTest.php
SpacePossum 4 years ago
parent
commit
d9cf3b9b80

+ 2 - 2
README.rst

@@ -821,7 +821,7 @@ Choose from the list of available rules:
   - ``separate`` (``'both'``, ``'bottom'``, ``'none'``, ``'top'``): whether the header should be
     separated from the file content with a new line; defaults to ``'both'``
 
-* **heredoc_indentation** [@PHP73Migration, @PHP74Migration]
+* **heredoc_indentation** [@PHP73Migration, @PHP74Migration, @PHP8Migration]
 
   Heredoc/nowdoc content must be properly indented. Requires PHP >= 7.3.
 
@@ -2016,7 +2016,7 @@ Choose from the list of available rules:
 
   Removes extra spaces between colon and case value.
 
-* **switch_continue_to_break** [@Symfony, @PhpCsFixer, @PHP73Migration, @PHP74Migration]
+* **switch_continue_to_break** [@Symfony, @PhpCsFixer, @PHP73Migration, @PHP74Migration, @PHP8Migration]
 
   Switch case must not be ended with ``continue`` but with ``break``.
 

+ 0 - 2
UPGRADE.md

@@ -1,5 +1,3 @@
-
-
 UPGRADE GUIDE FROM 1.x to 2.0
 =============================
 

+ 4 - 2
src/Linter/TokenizerLinter.php

@@ -27,7 +27,7 @@ final class TokenizerLinter implements LinterInterface
 {
     public function __construct()
     {
-        if (false === \defined('TOKEN_PARSE')) {
+        if (false === \defined('TOKEN_PARSE') || false === class_exists(\CompileError::class)) {
             throw new UnavailableLinterException('Cannot use tokenizer as linter.');
         }
     }
@@ -55,7 +55,7 @@ final class TokenizerLinter implements LinterInterface
     {
         try {
             // To lint, we will parse the source into Tokens.
-            // During that process, it might throw ParseError.
+            // During that process, it might throw a ParseError or CompileError.
             // If it won't, cache of tokenized version of source will be kept, which is great for Runner.
             // Yet, first we need to clear already existing cache to not hit it and lint the code indeed.
             $codeHash = CodeHasher::calculateCodeHash($source);
@@ -65,6 +65,8 @@ final class TokenizerLinter implements LinterInterface
             return new TokenizerLintingResult();
         } catch (\ParseError $e) {
             return new TokenizerLintingResult($e);
+        } catch (\CompileError $e) {
+            return new TokenizerLintingResult($e);
         }
     }
 }

+ 8 - 3
src/Linter/TokenizerLintingResult.php

@@ -20,11 +20,11 @@ namespace PhpCsFixer\Linter;
 final class TokenizerLintingResult implements LintingResultInterface
 {
     /**
-     * @var null|\ParseError
+     * @var null|\Error
      */
     private $error;
 
-    public function __construct(\ParseError $error = null)
+    public function __construct(\Error $error = null)
     {
         $this->error = $error;
     }
@@ -36,10 +36,15 @@ final class TokenizerLintingResult implements LintingResultInterface
     {
         if (null !== $this->error) {
             throw new LintingException(
-                sprintf('PHP Parse error: %s on line %d.', $this->error->getMessage(), $this->error->getLine()),
+                sprintf('%s: %s on line %d.', $this->getMessagePrefix(), $this->error->getMessage(), $this->error->getLine()),
                 $this->error->getCode(),
                 $this->error
             );
         }
     }
+
+    private function getMessagePrefix()
+    {
+        return \get_class($this->error);
+    }
 }

+ 1 - 1
src/RuleSet.php

@@ -385,7 +385,7 @@ final class RuleSet implements RuleSetInterface
             'use_arrow_functions' => true,
         ],
         '@PHP8Migration' => [
-            '@PHP71Migration' => true,
+            '@PHP73Migration' => true,
             'no_unset_cast' => true,
             'normalize_index_brace' => true,
         ],

+ 0 - 8
tests/Fixer/Alias/NoAliasFunctionsFixerTest.php

@@ -89,14 +89,6 @@ final class NoAliasFunctionsFixerTest extends AbstractFixerTestCase
                     "<?php \\{$master}(\$a);",
                     "<?php \\{$alias}(\$a);",
                 ];
-                $cases[] = [
-                    "<?php \$ref = &{$master}(\$a);",
-                    "<?php \$ref = &{$alias}(\$a);",
-                ];
-                $cases[] = [
-                    "<?php \$ref = &\\{$master}(\$a);",
-                    "<?php \$ref = &\\{$alias}(\$a);",
-                ];
                 $cases[] = [
                     "<?php {$master}
                                 (\$a);",

+ 0 - 19
tests/Fixer/Alias/SetTypeToCastFixerTest.php

@@ -224,25 +224,6 @@ $foo#5
         ];
     }
 
-    /**
-     * @param string      $expected
-     * @param null|string $input
-     *
-     * @requires PHP 7.0
-     * @dataProvider provideFix70Cases
-     */
-    public function testFix70($expected, $input = null)
-    {
-        $this->doTest($expected, $input);
-    }
-
-    public function provideFix70Cases()
-    {
-        yield 'complex' => [
-            '<?php settype($foo + 1, "null");',
-        ];
-    }
-
     /**
      * @param string $expected
      * @param string $input

+ 2 - 0
tests/Fixer/Basic/EncodingFixerTest.php

@@ -41,6 +41,8 @@ final class EncodingFixerTest extends AbstractFixerTestCase
         yield $this->prepareTestCase('test-utf8.case2.php', 'test-utf8.case2-bom.php');
 
         yield ['<?php'];
+
+        yield ['<?php '];
     }
 
     private function prepareTestCase($expectedFilename, $inputFilename = null)

+ 0 - 3
tests/Fixer/Casing/LowercaseStaticReferenceFixerTest.php

@@ -175,9 +175,6 @@ final class LowercaseStaticReferenceFixerTest extends AbstractFixerTestCase
             [
                 '<?php class Foo extends Bar { public function baz() : Self\Qux {} }',
             ],
-            [
-                '<?php namespace Parent;',
-            ],
         ];
     }
 

+ 4 - 4
tests/Fixer/Casing/MagicConstantCasingFixerTest.php

@@ -88,15 +88,15 @@ final class MagicConstantCasingFixerTest extends AbstractFixerTestCase
      * @param string      $expected
      * @param null|string $input
      *
-     * @requires PHP 7.0
-     * @dataProvider provideFix70Cases
+     * @requires PHP 7.4
+     * @dataProvider provideFix74Cases
      */
-    public function testFix70($expected, $input = null)
+    public function testFix74($expected, $input = null)
     {
         $this->doTest($expected, $input);
     }
 
-    public function provideFix70Cases()
+    public function provideFix74Cases()
     {
         return [
             [

Some files were not shown because too many files changed in this diff