Updated Rector to commit a533e70fca40571ab9504fbb857205b2be2eccb6

a533e70fca [Php80] Add DoctrineCoverterterAttributeDecorator to convert "false"/"true" string to false/true on nullable arg on Doctrine\ORM\Mapping\Column (#5629)
This commit is contained in:
Tomas Votruba 2024-02-17 10:59:16 +00:00
parent 531af37084
commit 476bd88e73
8 changed files with 80 additions and 11 deletions

View File

@ -0,0 +1,38 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\AttributeDecorator;
use PhpParser\Node\Attribute;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar\String_;
use Rector\Php80\Contract\ConverterAttributeDecoratorInterface;
final class DoctrineCoverterterAttributeDecorator implements ConverterAttributeDecoratorInterface
{
public function getAttributeName() : string
{
return 'Doctrine\\ORM\\Mapping\\Column';
}
public function decorate(Attribute $attribute) : void
{
foreach ($attribute->args as $arg) {
if (!$arg->name instanceof Identifier) {
continue;
}
if ($arg->name->toString() !== 'nullable') {
continue;
}
$value = $arg->value;
if (!$value instanceof String_) {
continue;
}
if (!\in_array($value->value, ['true', 'false'], \true)) {
continue;
}
$arg->value = $value->value === 'true' ? new ConstFetch(new Name('true')) : new ConstFetch(new Name('false'));
break;
}
}
}

View File

@ -4,7 +4,8 @@ declare (strict_types=1);
namespace Rector\Php80\AttributeDecorator;
use PhpParser\Node\Attribute;
final class SensioParamConverterAttributeDecorator
use Rector\Php80\Contract\ConverterAttributeDecoratorInterface;
final class SensioParamConverterAttributeDecorator implements ConverterAttributeDecoratorInterface
{
public function getAttributeName() : string
{

View File

@ -0,0 +1,11 @@
<?php
declare (strict_types=1);
namespace Rector\Php80\Contract;
use PhpParser\Node\Attribute;
interface ConverterAttributeDecoratorInterface
{
public function getAttributeName() : string;
public function decorate(Attribute $attribute) : void;
}

View File

@ -5,17 +5,20 @@ namespace Rector\Php80\NodeManipulator;
use PhpParser\Node\AttributeGroup;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\Php80\AttributeDecorator\SensioParamConverterAttributeDecorator;
use Rector\Php80\Contract\ConverterAttributeDecoratorInterface;
final class AttributeGroupNamedArgumentManipulator
{
/**
* @var ConverterAttributeDecoratorInterface[]
* @readonly
* @var \Rector\Php80\AttributeDecorator\SensioParamConverterAttributeDecorator
*/
private $sensioParamConverterAttributeDecorator;
public function __construct(SensioParamConverterAttributeDecorator $sensioParamConverterAttributeDecorator)
private $converterAttributeDecorators;
/**
* @param ConverterAttributeDecoratorInterface[] $converterAttributeDecorators
*/
public function __construct(array $converterAttributeDecorators)
{
$this->sensioParamConverterAttributeDecorator = $sensioParamConverterAttributeDecorator;
$this->converterAttributeDecorators = $converterAttributeDecorators;
}
/**
* @param AttributeGroup[] $attributeGroups
@ -25,10 +28,12 @@ final class AttributeGroupNamedArgumentManipulator
foreach ($attributeGroups as $attributeGroup) {
foreach ($attributeGroup->attrs as $attr) {
$phpAttributeName = $attr->name->getAttribute(AttributeKey::PHP_ATTRIBUTE_NAME);
if ($this->sensioParamConverterAttributeDecorator->getAttributeName() !== $phpAttributeName) {
continue;
foreach ($this->converterAttributeDecorators as $converterAttributeDecorator) {
if ($converterAttributeDecorator->getAttributeName() !== $phpAttributeName) {
continue;
}
$converterAttributeDecorator->decorate($attr);
}
$this->sensioParamConverterAttributeDecorator->decorate($attr);
}
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '2ccf2dedae865100f20bd8fb649625cabb0e4ed3';
public const PACKAGE_VERSION = 'a533e70fca40571ab9504fbb857205b2be2eccb6';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2024-02-16 22:58:25';
public const RELEASE_DATE = '2024-02-17 11:56:55';
/**
* @var int
*/

View File

@ -100,6 +100,10 @@ use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StmtKeyNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\Php80\AttributeDecorator\DoctrineCoverterterAttributeDecorator;
use Rector\Php80\AttributeDecorator\SensioParamConverterAttributeDecorator;
use Rector\Php80\Contract\ConverterAttributeDecoratorInterface;
use Rector\Php80\NodeManipulator\AttributeGroupNamedArgumentManipulator;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\AnnotationToAttributeMapper\ArrayAnnotationToAttributeMapper;
use Rector\PhpAttribute\AnnotationToAttributeMapper\ArrayItemNodeAnnotationToAttributeMapper;
@ -234,6 +238,10 @@ final class LazyContainerFactory
* @var array<class-string<SkipVoterInterface>>
*/
private const SKIP_VOTER_CLASSES = [ClassSkipVoter::class];
/**
* @var array<class-string<ConverterAttributeDecoratorInterface>>
*/
private const CONVERTER_ATTRIBUTE_DECORATOR_CLASSES = [SensioParamConverterAttributeDecorator::class, DoctrineCoverterterAttributeDecorator::class];
/**
* @api used as next rectorConfig factory
*/
@ -303,6 +311,8 @@ final class LazyContainerFactory
$rectorConfig->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class);
$rectorConfig->when(Skipper::class)->needs('$skipVoters')->giveTagged(SkipVoterInterface::class);
$this->registerTagged($rectorConfig, self::SKIP_VOTER_CLASSES, SkipVoterInterface::class);
$rectorConfig->when(AttributeGroupNamedArgumentManipulator::class)->needs('$converterAttributeDecorators')->giveTagged(ConverterAttributeDecoratorInterface::class);
$this->registerTagged($rectorConfig, self::CONVERTER_ATTRIBUTE_DECORATOR_CLASSES, ConverterAttributeDecoratorInterface::class);
$rectorConfig->afterResolving(AbstractRector::class, static function (AbstractRector $rector, Container $container) : void {
$rector->autowire($container->get(NodeNameResolver::class), $container->get(NodeTypeResolver::class), $container->get(SimpleCallableNodeTraverser::class), $container->get(NodeFactory::class), $container->get(Skipper::class), $container->get(NodeComparator::class), $container->get(CurrentFileProvider::class), $container->get(CreatedByRuleDecorator::class), $container->get(ChangedNodeScopeRefresher::class));
});

View File

@ -1847,7 +1847,9 @@ return array(
'Rector\\Php74\\Rector\\StaticCall\\ExportToReflectionFunctionRector' => $baseDir . '/rules/Php74/Rector/StaticCall/ExportToReflectionFunctionRector.php',
'Rector\\Php74\\Rector\\Ternary\\ParenthesizeNestedTernaryRector' => $baseDir . '/rules/Php74/Rector/Ternary/ParenthesizeNestedTernaryRector.php',
'Rector\\Php74\\Tokenizer\\ParenthesizedNestedTernaryAnalyzer' => $baseDir . '/rules/Php74/Tokenizer/ParenthesizedNestedTernaryAnalyzer.php',
'Rector\\Php80\\AttributeDecorator\\DoctrineCoverterterAttributeDecorator' => $baseDir . '/rules/Php80/AttributeDecorator/DoctrineCoverterterAttributeDecorator.php',
'Rector\\Php80\\AttributeDecorator\\SensioParamConverterAttributeDecorator' => $baseDir . '/rules/Php80/AttributeDecorator/SensioParamConverterAttributeDecorator.php',
'Rector\\Php80\\Contract\\ConverterAttributeDecoratorInterface' => $baseDir . '/rules/Php80/Contract/ConverterAttributeDecoratorInterface.php',
'Rector\\Php80\\Contract\\StrStartWithMatchAndRefactorInterface' => $baseDir . '/rules/Php80/Contract/StrStartWithMatchAndRefactorInterface.php',
'Rector\\Php80\\Contract\\ValueObject\\AnnotationToAttributeInterface' => $baseDir . '/rules/Php80/Contract/ValueObject/AnnotationToAttributeInterface.php',
'Rector\\Php80\\DocBlock\\PropertyPromotionDocBlockMerger' => $baseDir . '/rules/Php80/DocBlock/PropertyPromotionDocBlockMerger.php',

View File

@ -2066,7 +2066,9 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54
'Rector\\Php74\\Rector\\StaticCall\\ExportToReflectionFunctionRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/StaticCall/ExportToReflectionFunctionRector.php',
'Rector\\Php74\\Rector\\Ternary\\ParenthesizeNestedTernaryRector' => __DIR__ . '/../..' . '/rules/Php74/Rector/Ternary/ParenthesizeNestedTernaryRector.php',
'Rector\\Php74\\Tokenizer\\ParenthesizedNestedTernaryAnalyzer' => __DIR__ . '/../..' . '/rules/Php74/Tokenizer/ParenthesizedNestedTernaryAnalyzer.php',
'Rector\\Php80\\AttributeDecorator\\DoctrineCoverterterAttributeDecorator' => __DIR__ . '/../..' . '/rules/Php80/AttributeDecorator/DoctrineCoverterterAttributeDecorator.php',
'Rector\\Php80\\AttributeDecorator\\SensioParamConverterAttributeDecorator' => __DIR__ . '/../..' . '/rules/Php80/AttributeDecorator/SensioParamConverterAttributeDecorator.php',
'Rector\\Php80\\Contract\\ConverterAttributeDecoratorInterface' => __DIR__ . '/../..' . '/rules/Php80/Contract/ConverterAttributeDecoratorInterface.php',
'Rector\\Php80\\Contract\\StrStartWithMatchAndRefactorInterface' => __DIR__ . '/../..' . '/rules/Php80/Contract/StrStartWithMatchAndRefactorInterface.php',
'Rector\\Php80\\Contract\\ValueObject\\AnnotationToAttributeInterface' => __DIR__ . '/../..' . '/rules/Php80/Contract/ValueObject/AnnotationToAttributeInterface.php',
'Rector\\Php80\\DocBlock\\PropertyPromotionDocBlockMerger' => __DIR__ . '/../..' . '/rules/Php80/DocBlock/PropertyPromotionDocBlockMerger.php',