2021-03-21 00:16:21 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Php80\ValueObject;
|
2021-03-21 00:16:21 +01:00
|
|
|
|
2022-08-18 17:55:50 +00:00
|
|
|
use Rector\Php80\Contract\ValueObject\AnnotationToAttributeInterface;
|
2024-01-02 02:40:38 +00:00
|
|
|
use Rector\Validation\RectorAssert;
|
2024-04-01 16:51:34 +00:00
|
|
|
use RectorPrefix202404\Webmozart\Assert\Assert;
|
2022-08-18 17:55:50 +00:00
|
|
|
final class AnnotationToAttribute implements AnnotationToAttributeInterface
|
2021-03-21 00:16:21 +01:00
|
|
|
{
|
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2022-08-18 17:55:50 +00:00
|
|
|
* @var string
|
2021-03-21 00:16:21 +01:00
|
|
|
*/
|
2021-04-04 11:01:11 +02:00
|
|
|
private $tag;
|
2021-03-21 00:16:21 +01:00
|
|
|
/**
|
2023-06-11 23:01:39 +00:00
|
|
|
* @readonly
|
2022-08-18 17:55:50 +00:00
|
|
|
* @var string|null
|
2021-03-21 00:16:21 +01:00
|
|
|
*/
|
|
|
|
private $attributeClass;
|
2024-02-14 19:28:57 +00:00
|
|
|
/**
|
|
|
|
* @var string[]
|
|
|
|
* @readonly
|
|
|
|
*/
|
|
|
|
private $classReferenceFields = [];
|
|
|
|
/**
|
|
|
|
* @param string[] $classReferenceFields
|
|
|
|
*/
|
|
|
|
public function __construct(string $tag, ?string $attributeClass = null, array $classReferenceFields = [])
|
2021-03-21 00:16:21 +01:00
|
|
|
{
|
2021-04-04 11:01:11 +02:00
|
|
|
$this->tag = $tag;
|
2021-03-21 00:16:21 +01:00
|
|
|
$this->attributeClass = $attributeClass;
|
2024-02-14 19:28:57 +00:00
|
|
|
$this->classReferenceFields = $classReferenceFields;
|
2022-08-18 17:55:50 +00:00
|
|
|
RectorAssert::className($tag);
|
|
|
|
if (\is_string($attributeClass)) {
|
|
|
|
RectorAssert::className($attributeClass);
|
|
|
|
}
|
2024-02-14 19:28:57 +00:00
|
|
|
Assert::allString($classReferenceFields);
|
2021-03-21 00:16:21 +01:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getTag() : string
|
2021-03-21 00:16:21 +01:00
|
|
|
{
|
2021-04-04 11:01:11 +02:00
|
|
|
return $this->tag;
|
2021-03-21 00:16:21 +01:00
|
|
|
}
|
2021-05-09 20:15:43 +00:00
|
|
|
public function getAttributeClass() : string
|
2021-03-21 00:16:21 +01:00
|
|
|
{
|
2021-06-05 21:47:54 +00:00
|
|
|
if ($this->attributeClass === null) {
|
|
|
|
return $this->tag;
|
|
|
|
}
|
2021-03-21 00:16:21 +01:00
|
|
|
return $this->attributeClass;
|
|
|
|
}
|
2024-02-14 19:28:57 +00:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
|
|
|
public function getClassReferenceFields() : array
|
|
|
|
{
|
|
|
|
return $this->classReferenceFields;
|
|
|
|
}
|
2021-03-21 00:16:21 +01:00
|
|
|
}
|