[Php80] Do not remove Assert with no arg in AnnotationToAttributeRector (#733)

This commit is contained in:
Abdul Malik Ikhsan 2021-08-22 22:28:07 +07:00 committed by GitHub
parent ea9cddd31b
commit d72a5999ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -0,0 +1,38 @@
<?php
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\FixtureAutoImported;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
class User
{
/**
* @ORM\Column(type="string", length=27)
* @Assert\NotBlank()
* @Assert\Length(max=27)
*/
private string $email;
}
?>
-----
<?php
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\FixtureAutoImported;
use Doctrine\ORM\Mapping\Column;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\ORM\Mapping as ORM;
class User
{
/**
* @Assert\NotBlank()
* @Assert\Length(max=27)
*/
#[Column(type: 'string', length: 27)]
private string $email;
}
?>

View File

@ -57,7 +57,12 @@ final class ConvertedAnnotationToAttributeParentRemover
DoctrineAnnotationTagValueNode $doctrineAnnotationTagValueNode,
array $annotationsToAttributes
): bool {
foreach ($doctrineAnnotationTagValueNode->getValues() as $nodeValue) {
$nodeValues = $doctrineAnnotationTagValueNode->getValues();
if ($nodeValues === []) {
return false;
}
foreach ($nodeValues as $nodeValue) {
if (! $nodeValue instanceof CurlyListNode) {
return false;
}