diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php deleted file mode 100644 index efe19291a02..00000000000 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php +++ /dev/null @@ -1,23 +0,0 @@ -entityManager = $entityManager; - } -} - -?> diff --git a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php.inc b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php.inc index ab790a0ffab..10491249128 100644 --- a/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php.inc +++ b/rules-tests/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorRector/Fixture/include_trait_as_well.php.inc @@ -33,7 +33,7 @@ final class IncludeTraitAsWell { use TraitUsingEntityManager; - private EntityManagerInterface $entityManager; + private \Doctrine\ORM\EntityManagerInterface $entityManager; public function __construct(EntityManagerInterface $entityManager) { diff --git a/rules/Php74/Guard/PropertyTypeChangeGuard.php b/rules/Php74/Guard/PropertyTypeChangeGuard.php index d1a63dfa35e..dd9e2af0b4b 100644 --- a/rules/Php74/Guard/PropertyTypeChangeGuard.php +++ b/rules/Php74/Guard/PropertyTypeChangeGuard.php @@ -41,7 +41,7 @@ public function isLegal( $propertyName = $this->nodeNameResolver->getName($property); - if ($this->propertyManipulator->isUsedByTrait($classReflection, $propertyName)) { + if ($this->propertyManipulator->hasTraitWitHSameProperty($classReflection, $propertyName)) { return false; } diff --git a/scoper.php b/scoper.php index 39a1ead71a9..86d07caa63c 100644 --- a/scoper.php +++ b/scoper.php @@ -137,11 +137,7 @@ static function (string $filePath, string $prefix, string $content): string { return $content; } - return str_replace( - "'" . $prefix . "\\", - "'\\", - $content - ); + return str_replace("'" . $prefix . '\\', "'\\", $content); }, static function (string $filePath, string $prefix, string $content): string { diff --git a/src/NodeManipulator/PropertyManipulator.php b/src/NodeManipulator/PropertyManipulator.php index 09030371c1b..29fa1e76bca 100644 --- a/src/NodeManipulator/PropertyManipulator.php +++ b/src/NodeManipulator/PropertyManipulator.php @@ -144,6 +144,17 @@ public function isUsedByTrait(ClassReflection $classReflection, string $property return false; } + public function hasTraitWitHSameProperty(ClassReflection $classReflection, string $propertyName): bool + { + foreach ($classReflection->getTraits() as $traitUse) { + if ($traitUse->hasProperty($propertyName)) { + return true; + } + } + + return false; + } + private function isPropertyAssignedOnlyInConstructor( Class_ $class, string $propertyName,