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

Fix for AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector #321

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
final class Trainer
{
#[ORM\OneToMany]
private $trainings;

public function getTrainings(): Collection
{
return $this->trainings;
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
final class Trainer
{
#[ORM\OneToMany]
private $trainings;

public function getTrainings(): Collection
{
return $this->trainings;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
final class Trainer
{
#[ORM\Column(type: 'integer')]
private int $id = 1;

public function getId(): int
{
return $this->id;
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
final class Trainer
{
#[ORM\Column(type: 'integer')]
private int $id = 1;

public function getId(): int
{
return $this->id;
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training;

#[ORM\Entity]
final class Trainer
{
#[ORM\OneToMany(targetEntity: Training::class, mappedBy:"trainer")]
private $trainings;

public function __set($name, $value)
{
$this->$name = $value;
}

public function __get($name)
{
return $this->$name;
}

public function __isset($name)
{
return isset($this->$name);
}

public function getTrainings(): Collection
{
return $this->trainings;
}
}

?>
-----
<?php

namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\OneToMany;

use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training;

#[ORM\Entity]
final class Trainer
{
#[ORM\OneToMany(targetEntity: Training::class, mappedBy:"trainer")]
private $trainings;

public function __set($name, $value)
{
$this->$name = $value;
}

public function __get($name)
{
return $this->$name;
}

public function __isset($name)
{
return isset($this->$name);
}

/**
* @return \Doctrine\Common\Collections\Collection<int, \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training>
*/
public function getTrainings(): Collection
{
return $this->trainings;
}
}

?>
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node

foreach ($node->getMethods() as $classMethod) {
if ($this->classMethodReturnTypeOverrideGuard->shouldSkipClassMethod($classMethod, $scope)) {
return null;
continue;
}

$property = $this->methodUniqueReturnedPropertyResolver->resolve($node, $classMethod);
Expand All @@ -110,7 +110,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node
$collectionObjectType = $this->getCollectionObjectTypeFromToManyAttribute($property);

if (! $collectionObjectType instanceof FullyQualifiedObjectType) {
return null;
continue;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$hasChanged flag before and after changed, to be verified after loop to return node or null is needed

}

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($classMethod);
Expand Down
Loading