Browse Source

Merge branch 'master' into 3.0

# Conflicts:
#	phpstan.neon
#	tests/ConfigTest.php
#	tests/FixerConfiguration/FixerConfigurationResolverRootlessTest.php
Dariusz Ruminski 3 years ago
parent
commit
3a109d0b7c

+ 0 - 7
phpstan.neon

@@ -12,7 +12,6 @@ parameters:
         - tests/Fixtures
     ignoreErrors:
         - '/^Constant T_NAME_(RELATIVE|FULLY_QUALIFIED|QUALIFIED) not found\.$/'
-        - '/assertInstanceOf\(\) expects class-string.*, string given/'
         -
             message: '/^Strict comparison using !== between ''@git-commit@'' and ''@git-commit@'' will always evaluate to false\.$/'
             path: src/Console/Application.php
@@ -23,17 +22,11 @@ parameters:
         - # https://github.com/phpstan/phpstan/issues/1215
             message: '/^Strict comparison using === between false and string will always evaluate to false\.$/'
             path: src/Fixer/StringNotation/NoTrailingWhitespaceInStringFixer.php
-        -
-            message: '/^Property .*::\$indicator .* does not accept null\.$/'
-            path: tests/Indicator/PhpUnitTestCaseIndicatorTest.php
         -
             message: '/^Constant T_ATTRIBUTE not found\.$/'
             path: src/Tokenizer/Transformer/AttributeTransformer.php
         -
             message: '/^\$this\(PhpCsFixer\\Tokenizer\\Tokens\) does not accept PhpCsFixer\\Tokenizer\\Token\|null\.$/'
             path: src/Tokenizer/Tokens.php
-        -
-            message: '/^Class Test\dConfig not found\.$/'
-            path: tests/Console/ConfigurationResolverTest.php
 
     tipsOfTheDay: false

+ 4 - 3
src/Tokenizer/Transformer/TypeAlternationTransformer.php

@@ -20,7 +20,8 @@ use PhpCsFixer\Tokenizer\Token;
 use PhpCsFixer\Tokenizer\Tokens;
 
 /**
- * Transform `|` operator into CT::T_TYPE_ALTERNATION in `} catch (ExceptionType1 | ExceptionType2 $e) {`.
+ * Transform `|` operator into CT::T_TYPE_ALTERNATION in `function foo(Type1 | Type2 $x) {`
+ *                                                    or `} catch (ExceptionType1 | ExceptionType2 $e) {`.
  *
  * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  *
@@ -33,7 +34,7 @@ final class TypeAlternationTransformer extends AbstractTransformer
      */
     public function getPriority(): int
     {
-        // needs to run after TypeColonTransformer
+        // needs to run after ArrayTypehintTransformer and TypeColonTransformer
         return -15;
     }
 
@@ -56,7 +57,7 @@ final class TypeAlternationTransformer extends AbstractTransformer
 
         $prevIndex = $tokens->getPrevMeaningfulToken($index);
 
-        if (!$tokens[$prevIndex]->isGivenKind(T_STRING)) {
+        if (!$tokens[$prevIndex]->isGivenKind([T_STRING, CT::T_ARRAY_TYPEHINT])) {
             return;
         }
 

+ 2 - 2
tests/Console/ConfigurationResolverTest.php

@@ -167,7 +167,7 @@ final class ConfigurationResolverTest extends TestCase
         $resolver = $this->createConfigurationResolver(['path' => [$dir.\DIRECTORY_SEPARATOR.'foo.php']]);
 
         static::assertSame($dir.\DIRECTORY_SEPARATOR.'.php-cs-fixer.dist.php', $resolver->getConfigFile());
-        static::assertInstanceOf(\Test1Config::class, $resolver->getConfig());
+        static::assertInstanceOf(\Test1Config::class, $resolver->getConfig()); // @phpstan-ignore-line to avoid `Class Test1Config not found.`
     }
 
     public function testResolveConfigFileSpecified(): void
@@ -177,7 +177,7 @@ final class ConfigurationResolverTest extends TestCase
         $resolver = $this->createConfigurationResolver(['config' => $file]);
 
         static::assertSame($file, $resolver->getConfigFile());
-        static::assertInstanceOf(\Test4Config::class, $resolver->getConfig());
+        static::assertInstanceOf(\Test4Config::class, $resolver->getConfig()); // @phpstan-ignore-line to avoid `Class Test4Config not found.`
     }
 
     /**

+ 13 - 0
tests/Fixer/ClassNotation/VisibilityRequiredFixerTest.php

@@ -822,5 +822,18 @@ AB# <- this is the name
         yield [
             '<?php class Foo { private int | /* or empty */ null $foo; }',
         ];
+
+        yield [
+            '<?php class Foo { private array|null $foo; }',
+        ];
+
+        yield [
+            '<?php class Foo { private null|array $foo; }',
+        ];
+
+        yield [
+            '<?php class Foo { public static null|array $foo; }',
+            '<?php class Foo { static null|array $foo; }',
+        ];
     }
 }

+ 1 - 1
tests/Indicator/PhpUnitTestCaseIndicatorTest.php

@@ -27,7 +27,7 @@ use PhpCsFixer\Tokenizer\Tokens;
 final class PhpUnitTestCaseIndicatorTest extends TestCase
 {
     /**
-     * @var PhpUnitTestCaseIndicator
+     * @var null|PhpUnitTestCaseIndicator
      */
     private $indicator;
 

+ 24 - 0
tests/Tokenizer/Transformer/TypeAlternationTransformerTest.php

@@ -224,5 +224,29 @@ class Number
                 35 => CT::T_TYPE_ALTERNATION,
             ],
         ];
+
+        yield 'array as first element of types' => [
+            '<?php function foo(array|bool|null $foo) {}',
+            [
+                6 => CT::T_TYPE_ALTERNATION,
+                8 => CT::T_TYPE_ALTERNATION,
+            ],
+        ];
+
+        yield 'array as middle element of types' => [
+            '<?php function foo(null|array|bool $foo) {}',
+            [
+                6 => CT::T_TYPE_ALTERNATION,
+                8 => CT::T_TYPE_ALTERNATION,
+            ],
+        ];
+
+        yield 'array as last element of types' => [
+            '<?php function foo(null|bool|array $foo) {}',
+            [
+                6 => CT::T_TYPE_ALTERNATION,
+                8 => CT::T_TYPE_ALTERNATION,
+            ],
+        ];
     }
 }