Skip to content

Commit

Permalink
Add typed property, if traits do not duplicate the property
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jan 9, 2025
1 parent 1c39637 commit b5ea2db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 30 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ final class IncludeTraitAsWell
{
use TraitUsingEntityManager;

private EntityManagerInterface $entityManager;
private \Doctrine\ORM\EntityManagerInterface $entityManager;

public function __construct(EntityManagerInterface $entityManager)
{
Expand Down
2 changes: 1 addition & 1 deletion rules/Php74/Guard/PropertyTypeChangeGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
6 changes: 1 addition & 5 deletions scoper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/NodeManipulator/PropertyManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b5ea2db

Please sign in to comment.