From e46b353b78f8b4ab2ba5dc55e585e039da24b44a Mon Sep 17 00:00:00 2001 From: Geert Eltink Date: Sun, 25 Oct 2020 08:11:22 +0100 Subject: [PATCH] fix: intersection type support Fixes #6 Signed-off-by: Geert Eltink --- src/LaminasCodingStandard/ruleset.xml | 10 +++- test/expected-report.txt | 8 ++-- test/fixable/9.GenericTypeHintSyntax.php | 58 ++++++++++++++++++++++++ test/fixed/9.GenericTypeHintSyntax.php | 55 ++++++++++++++++++++++ 4 files changed, 125 insertions(+), 6 deletions(-) diff --git a/src/LaminasCodingStandard/ruleset.xml b/src/LaminasCodingStandard/ruleset.xml index 5399a3e..05939e1 100644 --- a/src/LaminasCodingStandard/ruleset.xml +++ b/src/LaminasCodingStandard/ruleset.xml @@ -797,17 +797,23 @@ + - - + + + + + + + diff --git a/test/expected-report.txt b/test/expected-report.txt index 76bff45..9e633ce 100644 --- a/test/expected-report.txt +++ b/test/expected-report.txt @@ -15,7 +15,7 @@ test/fixable/4.1.ExtendsAndImplements.php 6 0 test/fixable/4.2.UsingTraits.php 5 0 test/fixable/4.3.PropertiesAndConstants.php 7 0 test/fixable/4.4.MethodsAndFunctions.php 26 0 -test/fixable/4.5.MethodAndFunctionArguments.php 66 0 +test/fixable/4.5.MethodAndFunctionArguments.php 68 0 test/fixable/4.6.AbstractFinalAndStatic.php 5 0 test/fixable/4.7.MethodAndFunctionCalls.php 11 0 test/fixable/4.ClassesPropertiesAndMethods.php 34 0 @@ -33,11 +33,11 @@ test/fixable/6.Operators.php 97 0 test/fixable/7.Closures.php 2 0 test/fixable/8.AnonymousClasses.php 1 0 test/fixable/9.CommentingAndDocBlocks.php 17 0 -test/fixable/9.GenericTypeHintSyntax.php 4 0 +test/fixable/9.GenericTypeHintSyntax.php 5 0 ---------------------------------------------------------------------- -A TOTAL OF 566 ERRORS AND 2 WARNINGS WERE FOUND IN 31 FILES +A TOTAL OF 569 ERRORS AND 2 WARNINGS WERE FOUND IN 31 FILES ---------------------------------------------------------------------- -PHPCBF CAN FIX 483 OF THESE SNIFF VIOLATIONS AUTOMATICALLY +PHPCBF CAN FIX 486 OF THESE SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------- diff --git a/test/fixable/9.GenericTypeHintSyntax.php b/test/fixable/9.GenericTypeHintSyntax.php index 10f4101..5753770 100644 --- a/test/fixable/9.GenericTypeHintSyntax.php +++ b/test/fixable/9.GenericTypeHintSyntax.php @@ -8,7 +8,9 @@ declare(strict_types=1); +use Generic; use IteratorAggregate; +use Traversable; class GenericTypeHintSyntax { @@ -33,4 +35,60 @@ public function doSomethingWithArray(array $config): void { $this->config = $config; } + + /** + * @param Generic $a + */ + public function genericWithoutItemsSpecification(Generic $a) + { + } + + /** + * @param array[]&Traversable $a + */ + public function traversableIntersection(Traversable $a) + { + } + + /** + * @param Traversable&array[] $a + */ + public function traversableIntersectionDifferentOrder(Traversable $a) + { + } + + /** + * @param null|Traversable $a + */ + public function traversableNull(?Traversable $a) + { + } + + /** + * @param array|array $a + */ + public function unionWithSameBase(array $a) + { + } + + /** + * @param array|array|array $a + */ + public function unionWithSameBaseAndMoreTypes(array $a) + { + } + + /** + * @param array|bool[] $a + */ + public function unionWithSameBaseToo(array $a) + { + } + + /** + * @param array|array|array|null $a + */ + public function unionWithSameNullableBase(?array $a) + { + } } diff --git a/test/fixed/9.GenericTypeHintSyntax.php b/test/fixed/9.GenericTypeHintSyntax.php index 10f4101..aa8565e 100644 --- a/test/fixed/9.GenericTypeHintSyntax.php +++ b/test/fixed/9.GenericTypeHintSyntax.php @@ -8,7 +8,9 @@ declare(strict_types=1); +use Generic; use IteratorAggregate; +use Traversable; class GenericTypeHintSyntax { @@ -33,4 +35,57 @@ public function doSomethingWithArray(array $config): void { $this->config = $config; } + + /** + * @param Generic $a + */ + public function genericWithoutItemsSpecification(Generic $a) + { + } + + /** + * @param array[]&Traversable $a + */ + public function traversableIntersection(Traversable $a) + { + } + + /** + * @param Traversable&array[] $a + */ + public function traversableIntersectionDifferentOrder(Traversable $a) + { + } + + public function traversableNull(?Traversable $a) + { + } + + /** + * @param array|array $a + */ + public function unionWithSameBase(array $a) + { + } + + /** + * @param array|array|array $a + */ + public function unionWithSameBaseAndMoreTypes(array $a) + { + } + + /** + * @param array|bool[] $a + */ + public function unionWithSameBaseToo(array $a) + { + } + + /** + * @param array|array|array|null $a + */ + public function unionWithSameNullableBase(?array $a) + { + } }