2022-08-18 17:55:50 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare (strict_types=1);
|
|
|
|
namespace Rector\Php80\ValueObject;
|
|
|
|
|
|
|
|
use Rector\Php80\Contract\ValueObject\AnnotationToAttributeInterface;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\Validation\RectorAssert;
|
2022-08-18 17:55:50 +00:00
|
|
|
final class NestedAnnotationToAttribute implements AnnotationToAttributeInterface
|
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2022-10-15 22:31:48 +00:00
|
|
|
* @var string
|
2022-08-18 17:55:50 +00:00
|
|
|
*/
|
2022-10-15 22:31:48 +00:00
|
|
|
private $tag;
|
2022-08-18 17:55:50 +00:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2022-08-18 17:55:50 +00:00
|
|
|
* @var bool
|
|
|
|
*/
|
|
|
|
private $removeOriginal = \false;
|
2023-06-08 22:00:17 +00:00
|
|
|
/**
|
|
|
|
* @var AnnotationPropertyToAttributeClass[]
|
|
|
|
*/
|
|
|
|
private $annotationPropertiesToAttributeClasses = [];
|
2022-08-18 17:55:50 +00:00
|
|
|
/**
|
2022-10-15 22:31:48 +00:00
|
|
|
* @param array<string, string>|string[]|AnnotationPropertyToAttributeClass[] $annotationPropertiesToAttributeClasses
|
2022-08-18 17:55:50 +00:00
|
|
|
*/
|
|
|
|
public function __construct(string $tag, array $annotationPropertiesToAttributeClasses, bool $removeOriginal = \false)
|
|
|
|
{
|
|
|
|
$this->tag = $tag;
|
|
|
|
$this->removeOriginal = $removeOriginal;
|
|
|
|
RectorAssert::className($tag);
|
2022-10-15 22:31:48 +00:00
|
|
|
// back compatibility for raw scalar values
|
|
|
|
foreach ($annotationPropertiesToAttributeClasses as $annotationProperty => $attributeClass) {
|
|
|
|
if ($attributeClass instanceof \Rector\Php80\ValueObject\AnnotationPropertyToAttributeClass) {
|
|
|
|
$this->annotationPropertiesToAttributeClasses[] = $attributeClass;
|
|
|
|
} else {
|
|
|
|
$this->annotationPropertiesToAttributeClasses[] = new \Rector\Php80\ValueObject\AnnotationPropertyToAttributeClass($attributeClass, $annotationProperty);
|
|
|
|
}
|
|
|
|
}
|
2022-08-18 17:55:50 +00:00
|
|
|
}
|
|
|
|
public function getTag() : string
|
|
|
|
{
|
|
|
|
return $this->tag;
|
|
|
|
}
|
|
|
|
/**
|
2022-10-15 22:31:48 +00:00
|
|
|
* @return AnnotationPropertyToAttributeClass[]
|
2022-08-18 17:55:50 +00:00
|
|
|
*/
|
|
|
|
public function getAnnotationPropertiesToAttributeClasses() : array
|
|
|
|
{
|
|
|
|
return $this->annotationPropertiesToAttributeClasses;
|
|
|
|
}
|
|
|
|
public function getAttributeClass() : string
|
|
|
|
{
|
|
|
|
return $this->tag;
|
|
|
|
}
|
|
|
|
public function shouldRemoveOriginal() : bool
|
|
|
|
{
|
|
|
|
return $this->removeOriginal;
|
|
|
|
}
|
2022-08-20 20:49:07 +00:00
|
|
|
public function hasExplicitParameters() : bool
|
|
|
|
{
|
2022-10-15 22:31:48 +00:00
|
|
|
foreach ($this->annotationPropertiesToAttributeClasses as $annotationPropertyToAttributeClass) {
|
|
|
|
if (\is_string($annotationPropertyToAttributeClass->getAnnotationProperty())) {
|
2022-08-20 20:49:07 +00:00
|
|
|
return \true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return \false;
|
|
|
|
}
|
2022-08-18 17:55:50 +00:00
|
|
|
}
|