From f0dd86dcd2e52513f82c5d09af15df036ff664f8 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 23 Aug 2024 09:45:39 +0200 Subject: [PATCH 1/2] Skip Doctrine collection properties in TypedPropertyFromAssignsRector as handled by doctrine rules --- .../Fixture/Doctrine/skip_collection.php.inc | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/Doctrine/skip_collection.php.inc diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/Doctrine/skip_collection.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/Doctrine/skip_collection.php.inc new file mode 100644 index 00000000000..85189284e3e --- /dev/null +++ b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector/Fixture/Doctrine/skip_collection.php.inc @@ -0,0 +1,13 @@ + Date: Fri, 23 Aug 2024 09:54:29 +0200 Subject: [PATCH 2/2] Skip collection properties --- .../Rector/Param/ExplicitNullableParamTypeRector.php | 2 +- .../Rector/Property/TypedPropertyFromAssignsRector.php | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php b/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php index 527f3fbc769..f85b909e68b 100644 --- a/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php +++ b/rules/Php84/Rector/Param/ExplicitNullableParamTypeRector.php @@ -4,7 +4,6 @@ namespace Rector\Php84\Rector\Param; -use PHPStan\Type\MixedType; use PhpParser\Node; use PhpParser\Node\ComplexType; use PhpParser\Node\Expr\ConstFetch; @@ -13,6 +12,7 @@ use PhpParser\Node\NullableType; use PhpParser\Node\Param; use PhpParser\Node\UnionType; +use PHPStan\Type\MixedType; use PHPStan\Type\TypeCombinator; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index 665a927ad35..7362e1b6c11 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -18,6 +18,8 @@ use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Contract\Rector\ConfigurableRectorInterface; use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover; +use Rector\Doctrine\CodeQuality\Enum\CollectionMapping; +use Rector\Doctrine\NodeAnalyzer\AttrinationFinder; use Rector\Php74\Guard\MakePropertyTypedGuard; use Rector\PhpParser\Node\Value\ValueResolver; use Rector\PHPStanStaticTypeMapper\Enum\TypeKind; @@ -60,7 +62,8 @@ public function __construct( private readonly ReflectionResolver $reflectionResolver, private readonly PhpDocInfoFactory $phpDocInfoFactory, private readonly ValueResolver $valueResolver, - private readonly StaticTypeMapper $staticTypeMapper + private readonly StaticTypeMapper $staticTypeMapper, + private readonly AttrinationFinder $attrinationFinder ) { } @@ -132,6 +135,11 @@ public function refactor(Node $node): ?Node continue; } + // doctrine colleciton is handled in doctrine rules + if ($this->attrinationFinder->hasByMany($property, CollectionMapping::TO_MANY_CLASSES)) { + continue; + } + if (! $classReflection instanceof ClassReflection) { $classReflection = $this->reflectionResolver->resolveClassReflection($node); }