Browse Source

Merge branch '2.16'

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

# Conflicts:
#	README.rst
SpacePossum 4 years ago
parent
commit
afaf95958d

+ 2 - 2
README.rst

@@ -848,7 +848,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.
 
@@ -2106,7 +2106,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

@@ -405,7 +405,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)

+ 24 - 6
tests/Fixer/Casing/LowercaseConstantsFixerTest.php

@@ -107,13 +107,8 @@ final class LowercaseConstantsFixerTest extends AbstractFixerTestCase
             ['<?php echo $null;'],
             ['<?php $x = False::foo();'],
             ['<?php namespace Foo\Null;'],
-            ['<?php use Foo\Null;'],
-            ['<?php use Foo\Null as Null;'],
-            ['<?php class True {} class False {} class Null {}'],
             ['<?php class Foo extends True {}'],
             ['<?php class Foo implements False {}'],
-            ['<?php Class Null { use True; }'],
-            ['<?php interface True {}'],
             ['<?php $foo instanceof True; $foo instanceof False; $foo instanceof Null;'],
             [
                 '<?php
@@ -128,6 +123,30 @@ final class LowercaseConstantsFixerTest extends AbstractFixerTestCase
             ['<?php Null/**/::test();'],
             ['<?php True//
                                 ::test();'],
+            ['<?php class Foo { public function Bar() { $this->False = 1; $this->True = 2; $this->Null = 3; } }'],
+        ];
+    }
+
+    /**
+     * @param string      $expected
+     * @param null|string $input
+     *
+     * @dataProvider provideFixPhp56Cases
+     * @requires PHP < 7
+     */
+    public function testFixPhp56($expected, $input = null)
+    {
+        $this->doTest($expected, $input);
+    }
+
+    public function provideFixPhp56Cases()
+    {
+        return [
+            ['<?php use Foo\Null;'],
+            ['<?php use Foo\Null as Null;'],
+            ['<?php class True {} class False {} class Null {}'],
+            ['<?php Class Null { use True; }'],
+            ['<?php interface True {}'],
             ['<?php trait False {}'],
             [
                 '<?php
@@ -139,7 +158,6 @@ final class LowercaseConstantsFixerTest extends AbstractFixerTestCase
         }
     }',
             ],
-            ['<?php class Foo { public function Bar() { $this->False = 1; $this->True = 2; $this->Null = 3; } }'],
         ];
     }
 }

+ 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;',
-            ],
         ];
     }
 

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