Skip to content

Commit

Permalink
[TypeDeclaration] Skip doctrine collection type (#3130)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Nov 29, 2022
1 parent e28b04a commit 02bdae0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 13 deletions.
14 changes: 1 addition & 13 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ parameters:
- '#Parameter \#1 \$tokenIterator \(Rector\\BetterPhpDocParser\\ValueObject\\Parser\\BetterTokenIterator\) of method Rector\\BetterPhpDocParser\\PhpDocParser\\BetterPhpDocParser\:\:parseTagValue\(\) should be contravariant with parameter \$tokens \(PHPStan\\PhpDocParser\\Parser\\TokenIterator\) of method PHPStan\\PhpDocParser\\Parser\\PhpDocParser\:\:parseTagValue\(\)#'
- '#Parameter \#1 \$nodes \(array<PhpParser\\Node\\Stmt\>\) of method Rector\\PostRector\\Rector\\(.*?)\:\:beforeTraverse\(\) should be contravariant with parameter \$nodes \(array<PhpParser\\Node\>\) of method PhpParser\\NodeVisitorAbstract\:\:beforeTraverse\(\)#'

# property changed else-where
-
message: '#If condition is always false#'
path: rules/TypeDeclaration/Rector/FunctionLike/ParamTypeDeclarationRector.php

# on purpose, allows empty tokens
- '#Rector\\BetterPhpDocParser\\ValueObject\\Parser\\BetterTokenIterator\:\:__construct\(\) does not call parent constructor from PHPStan\\PhpDocParser\\Parser\\TokenIterator#'
- '#Rector\\Comments\\NodeTraverser\\CommentRemovingNodeTraverser\:\:__construct\(\) does not call parent constructor from PhpParser\\NodeTraverser#'
Expand Down Expand Up @@ -340,7 +335,6 @@ parameters:

# complex detection
- '#Cognitive complexity for "Rector\\Core\\DependencyInjection\\Collector\\ConfigureCallValuesCollector\:\:addConfigureCallValues\(\)" is \d+, keep it under 10#'
- '#Cognitive complexity for "Rector\\TypeDeclaration\\Rector\\FunctionLike\\ParamTypeDeclarationRector\:\:refactorParam\(\)" is 11, keep it under 10#'

# return bool on change
- '#Method "(change|remove)(.*?)" returns bool type, so the name should start with is/has/was#'
Expand Down Expand Up @@ -707,11 +701,6 @@ parameters:
paths:
- rules/CodingStyle/Rector/ArrowFunction/StaticArrowFunctionRector.php
- rules/CodingStyle/Rector/Closure/StaticClosureRector.php
-
message: '#Content of method "getFunctionLikePhpDocInfo\(\)" is duplicated\. Use unique content or service instead#'
paths:
- rules/TypeDeclaration/TypeInferer/ParamTypeInferer/PHPUnitDataProviderParamTypeInferer.php
- packages/NodeTypeResolver/NodeTypeResolver/ParamTypeResolver.php

-
message: '#Content of method "resolveAssignVar\(\)" is duplicated\. Use unique content or service instead#'
Expand Down Expand Up @@ -789,6 +778,5 @@ parameters:
- '#Method Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddParamTypeBasedOnPHPUnitDataProviderRector\:\:resolveDataProviderPhpDocTagNode\(\) should return PHPStan\\PhpDocParser\\Ast\\PhpDoc\\PhpDocTagNode\|null but returns PHPStan\\PhpDocParser\\Ast\\Node\|null#'

# on purpose, as rule it about to be removed
- '#Class "Rector\\TypeDeclaration\\Rector\\ClassMethod\\AddArrayParamDocTypeRector" is missing @see annotation with test case class reference#'
- '#Register "Rector\\Php74\\Rector\\Property\\TypedPropertyRector" service to "php74\.php" config set#'
- '#Cognitive complexity for "Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorRector\:\:refactor\(\)" is 11, keep it under 10#'
- '#Cognitive complexity for "Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictConstructorRector\:\:refactor\(\)" is 13, keep it under 10#'
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector\Fixture;

use Doctrine\Common\Collections\ArrayCollection;

final class SkipDoctrineCollection
{
private $items;

public function __construct()
{
$this->items = new ArrayCollection();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Property\TypedPropertyFromStrictSetUpRector\Fixture;

final class SkipNoTestCase
{
private $value;

public function setUp()
{
$this->value = 1000;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectType;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Core\Php\PhpVersionProvider;
use Rector\Core\Rector\AbstractRector;
Expand Down Expand Up @@ -106,6 +107,12 @@ public function refactor(Node $node): ?Node
continue;
}

if ($propertyType instanceof ObjectType && $propertyType->isInstanceOf(
'Doctrine\Common\Collections\Collection'
)->yes()) {
continue;
}

if (! $this->propertyTypeOverrideGuard->isLegal($property)) {
continue;
}
Expand Down

0 comments on commit 02bdae0

Please sign in to comment.