Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle intersection types correctly #49

Merged
merged 1 commit into from Oct 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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">
geerteltink marked this conversation as resolved.
Show resolved Hide resolved
<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)
{
}
}