Skip to content

Commit

Permalink
Merge pull request #49 from geerteltink/fix/intersect-types
Browse files Browse the repository at this point in the history
Handle intersection types correctly
  • Loading branch information
geerteltink committed Oct 25, 2020
2 parents e636343 + e46b353 commit 8d5ba64
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/LaminasCodingStandard/ruleset.xml
Expand Up @@ -797,17 +797,23 @@
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
<!-- May use excessive whitespace to align comments after parameter names -->
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamName"/>
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>
</rule>

<!-- DocBlocks and comments SHOULD NOT be used for already typehinted arguments,
except arrays. -->
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint">
<properties>
<property name="enableNativeTypeHint" value="false"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
</rule>
Expand Down
8 changes: 4 additions & 4 deletions test/expected-report.txt
Expand Up @@ -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
Expand All @@ -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
----------------------------------------------------------------------


58 changes: 58 additions & 0 deletions test/fixable/9.GenericTypeHintSyntax.php
Expand Up @@ -8,7 +8,9 @@

declare(strict_types=1);

use Generic;
use IteratorAggregate;
use Traversable;

class GenericTypeHintSyntax
{
Expand All @@ -33,4 +35,60 @@ public function doSomethingWithArray(array $config): void
{
$this->config = $config;
}

/**
* @param Generic<array> $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<string>|array<int> $a
*/
public function unionWithSameBase(array $a)
{
}

/**
* @param array<string>|array<int>|array<bool> $a
*/
public function unionWithSameBaseAndMoreTypes(array $a)
{
}

/**
* @param array<int>|bool[] $a
*/
public function unionWithSameBaseToo(array $a)
{
}

/**
* @param array<string>|array<int>|array<bool>|null $a
*/
public function unionWithSameNullableBase(?array $a)
{
}
}
55 changes: 55 additions & 0 deletions test/fixed/9.GenericTypeHintSyntax.php
Expand Up @@ -8,7 +8,9 @@

declare(strict_types=1);

use Generic;
use IteratorAggregate;
use Traversable;

class GenericTypeHintSyntax
{
Expand All @@ -33,4 +35,57 @@ public function doSomethingWithArray(array $config): void
{
$this->config = $config;
}

/**
* @param Generic<array> $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<string>|array<int> $a
*/
public function unionWithSameBase(array $a)
{
}

/**
* @param array<string>|array<int>|array<bool> $a
*/
public function unionWithSameBaseAndMoreTypes(array $a)
{
}

/**
* @param array<int>|bool[] $a
*/
public function unionWithSameBaseToo(array $a)
{
}

/**
* @param array<string>|array<int>|array<bool>|null $a
*/
public function unionWithSameNullableBase(?array $a)
{
}
}

0 comments on commit 8d5ba64

Please sign in to comment.