mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-11 11:11:12 +01:00
AnnotationToAttributeRector: ensure bool param in attribute (#6254)
This commit is contained in:
parent
94cf4314e6
commit
a5a99317b7
@ -10,7 +10,9 @@ use PhpParser\Node\Attribute;
|
||||
use PhpParser\Node\AttributeGroup;
|
||||
use PhpParser\Node\Identifier;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFalseNode;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprIntegerNode;
|
||||
use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprTrueNode;
|
||||
use PHPStan\PhpDocParser\Ast\Node;
|
||||
use PHPStan\Type\Constant\ConstantBooleanType;
|
||||
use PHPStan\Type\Constant\ConstantFloatType;
|
||||
@ -104,6 +106,14 @@ final class PhpAttributeGroupFactory
|
||||
return $value->getValue();
|
||||
}
|
||||
|
||||
if ($value instanceof ConstExprTrueNode) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($value instanceof ConstExprFalseNode) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($value instanceof Node) {
|
||||
return (string) $value;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class EntityColumnAndAssertNotBlankWithBoolean
|
||||
{
|
||||
/**
|
||||
* @Assert\NotBlank(allowNull=true)
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @Assert\NotBlank(allowNull=false)
|
||||
*/
|
||||
public $surname;
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class EntityColumnAndAssertNotBlankWithBoolean
|
||||
{
|
||||
#[\Symfony\Component\Validator\Constraints\NotBlank(allowNull: true)]
|
||||
public $name;
|
||||
|
||||
#[\Symfony\Component\Validator\Constraints\NotBlank(allowNull: false)]
|
||||
public $surname;
|
||||
}
|
||||
|
||||
?>
|
@ -33,6 +33,10 @@ return static function (ContainerConfigurator $containerConfigurator): void {
|
||||
'Symfony\Component\Validator\Constraints\Range',
|
||||
'Symfony\Component\Validator\Constraints\Range'
|
||||
),
|
||||
new AnnotationToAttribute(
|
||||
'Symfony\Component\Validator\Constraints\NotBlank',
|
||||
'Symfony\Component\Validator\Constraints\NotBlank'
|
||||
),
|
||||
]),
|
||||
]]);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user