mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-14 20:39:43 +01:00
Updated Rector to commit 1ec42bcc33f0607533e08d75c47b589d89e7649e
1ec42bcc33
feat: add the option to use the annotation value as an argument to the attribute (#6468)
This commit is contained in:
parent
2769068789
commit
a6bbda76df
@ -199,7 +199,7 @@ CODE_SAMPLE
|
||||
if (!$this->reflectionProvider->hasClass($annotationToAttribute->getAttributeClass())) {
|
||||
continue;
|
||||
}
|
||||
$attributeGroups[] = $this->phpAttributeGroupFactory->createFromSimpleTag($annotationToAttribute);
|
||||
$attributeGroups[] = $this->phpAttributeGroupFactory->createFromSimpleTag($annotationToAttribute, $annotationToAttribute->getUseValueAsAttributeArgument() ? (string) $docNode->value : null);
|
||||
return PhpDocNodeTraverser::NODE_REMOVE;
|
||||
}
|
||||
return null;
|
||||
|
@ -21,14 +21,19 @@ final class AnnotationToAttribute implements AnnotationToAttributeInterface
|
||||
* @readonly
|
||||
*/
|
||||
private array $classReferenceFields = [];
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
private bool $useValueAsAttributeArgument = \false;
|
||||
/**
|
||||
* @param string[] $classReferenceFields
|
||||
*/
|
||||
public function __construct(string $tag, ?string $attributeClass = null, array $classReferenceFields = [])
|
||||
public function __construct(string $tag, ?string $attributeClass = null, array $classReferenceFields = [], bool $useValueAsAttributeArgument = \false)
|
||||
{
|
||||
$this->tag = $tag;
|
||||
$this->attributeClass = $attributeClass;
|
||||
$this->classReferenceFields = $classReferenceFields;
|
||||
$this->useValueAsAttributeArgument = $useValueAsAttributeArgument;
|
||||
RectorAssert::className($tag);
|
||||
if (\is_string($attributeClass)) {
|
||||
RectorAssert::className($attributeClass);
|
||||
@ -53,4 +58,8 @@ final class AnnotationToAttribute implements AnnotationToAttributeInterface
|
||||
{
|
||||
return $this->classReferenceFields;
|
||||
}
|
||||
public function getUseValueAsAttributeArgument() : bool
|
||||
{
|
||||
return $this->useValueAsAttributeArgument;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'fb169faf42679c046cd22ad865ae8097ccdb5799';
|
||||
public const PACKAGE_VERSION = '1ec42bcc33f0607533e08d75c47b589d89e7649e';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2024-11-24 21:45:17';
|
||||
public const RELEASE_DATE = '2024-11-24 18:23:37';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
@ -53,17 +53,21 @@ final class PhpAttributeGroupFactory
|
||||
$this->annotationToAttributeIntegerValueCaster = $annotationToAttributeIntegerValueCaster;
|
||||
$this->attributeArrayNameInliner = $attributeArrayNameInliner;
|
||||
}
|
||||
public function createFromSimpleTag(AnnotationToAttribute $annotationToAttribute) : AttributeGroup
|
||||
public function createFromSimpleTag(AnnotationToAttribute $annotationToAttribute, ?string $value = null) : AttributeGroup
|
||||
{
|
||||
return $this->createFromClass($annotationToAttribute->getAttributeClass());
|
||||
return $this->createFromClass($annotationToAttribute->getAttributeClass(), $value);
|
||||
}
|
||||
/**
|
||||
* @param AttributeName::*|string $attributeClass
|
||||
*/
|
||||
public function createFromClass(string $attributeClass) : AttributeGroup
|
||||
public function createFromClass(string $attributeClass, ?string $value = null) : AttributeGroup
|
||||
{
|
||||
$fullyQualified = new FullyQualified($attributeClass);
|
||||
$attribute = new Attribute($fullyQualified);
|
||||
if ($value !== null && $value !== '') {
|
||||
$arg = new Arg(new String_($value));
|
||||
$attribute->args = [$arg];
|
||||
}
|
||||
return new AttributeGroup([$attribute]);
|
||||
}
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user