-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add return doc block to Collection property's getter method by ToMany…
… attribute (#317)
- Loading branch information
1 parent
ab3daad
commit e5736dd
Showing
13 changed files
with
599 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
...ttributeRector/AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRectorTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture/*'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...nPropertyGetterByToManyAttributeRector/Fixture/ManyToMany/getter_with_return_type.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\ManyToMany; | ||
|
||
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\ManyToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
private $trainings; | ||
|
||
public function getTrainings(): Collection | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Fixture\ManyToMany; | ||
|
||
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\ManyToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
private $trainings; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<int, \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training> | ||
*/ | ||
public function getTrainings(): Collection | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
46 changes: 46 additions & 0 deletions
46
...onPropertyGetterByToManyAttributeRector/Fixture/OneToMany/getter_with_return_type.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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 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; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<int, \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training> | ||
*/ | ||
public function getTrainings(): Collection | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
46 changes: 46 additions & 0 deletions
46
...ropertyGetterByToManyAttributeRector/Fixture/OneToMany/getter_without_return_type.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?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 getTrainings() | ||
{ | ||
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; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<int, \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training> | ||
*/ | ||
public function getTrainings() | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
57 changes: 57 additions & 0 deletions
57
...ByToManyAttributeRector/Fixture/OneToMany/multiple_returned_collection_properties.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?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 $morningTrainings; | ||
|
||
#[ORM\OneToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
private $eveningTrainings; | ||
|
||
public function getTrainings(): Collection | ||
{ | ||
if (random_int(0, 1)) { | ||
return $this->morningTrainings; | ||
} | ||
|
||
return $this->eveningTrainings; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?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 $morningTrainings; | ||
|
||
#[ORM\OneToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
private $eveningTrainings; | ||
|
||
public function getTrainings(): Collection | ||
{ | ||
if (random_int(0, 1)) { | ||
return $this->morningTrainings; | ||
} | ||
|
||
return $this->eveningTrainings; | ||
} | ||
} | ||
|
||
?> |
41 changes: 41 additions & 0 deletions
41
...PropertyGetterByToManyAttributeRector/Fixture/OneToMany/not_a_collection_property.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; | ||
|
||
#[ORM\Entity] | ||
final class Trainer | ||
{ | ||
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; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; | ||
|
||
#[ORM\Entity] | ||
final class Trainer | ||
{ | ||
private $trainings; | ||
|
||
public function getTrainings(): Collection | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
41 changes: 41 additions & 0 deletions
41
...ollectionPropertyGetterByToManyAttributeRector/Fixture/OneToMany/not_entity_class.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; | ||
|
||
final class Trainer | ||
{ | ||
#[ORM\OneToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
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; | ||
use Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training; | ||
|
||
final class Trainer | ||
{ | ||
#[ORM\OneToMany(targetEntity:Training::class, mappedBy:"trainer")] | ||
private $trainings; | ||
|
||
public function getTrainings(): Collection | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
47 changes: 47 additions & 0 deletions
47
...nPropertyGetterByToManyAttributeRector/Fixture/OneToMany/with_invalid_return_type.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Fixture\OneToMany; | ||
|
||
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; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<\Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training> | ||
*/ | ||
public function getTrainings() | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAnnotationRector\Fixture\OneToMany; | ||
|
||
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; | ||
|
||
/** | ||
* @return \Doctrine\Common\Collections\Collection<int, \Rector\Doctrine\Tests\CodeQuality\Rector\Class_\AddReturnDocBlockToCollectionPropertyGetterByToManyAttributeRector\Source\Training> | ||
*/ | ||
public function getTrainings() | ||
{ | ||
return $this->trainings; | ||
} | ||
} | ||
|
||
?> |
Oops, something went wrong.