-
-
Notifications
You must be signed in to change notification settings - Fork 357
/
NestedAnnotationToAttribute.php
73 lines (61 loc) · 2.1 KB
/
NestedAnnotationToAttribute.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
declare(strict_types=1);
namespace Rector\Php80\ValueObject;
use Rector\Php80\Contract\ValueObject\AnnotationToAttributeInterface;
use Rector\Validation\RectorAssert;
final class NestedAnnotationToAttribute implements AnnotationToAttributeInterface
{
/**
* @var AnnotationPropertyToAttributeClass[]
*/
private array $annotationPropertiesToAttributeClasses = [];
/**
* @param array<string, string>|string[]|AnnotationPropertyToAttributeClass[] $annotationPropertiesToAttributeClasses
*/
public function __construct(
private readonly string $tag,
array $annotationPropertiesToAttributeClasses,
private readonly bool $removeOriginal = false,
) {
RectorAssert::className($tag);
// back compatibility for raw scalar values
foreach ($annotationPropertiesToAttributeClasses as $annotationProperty => $attributeClass) {
if ($attributeClass instanceof AnnotationPropertyToAttributeClass) {
$this->annotationPropertiesToAttributeClasses[] = $attributeClass;
} else {
$this->annotationPropertiesToAttributeClasses[] = new AnnotationPropertyToAttributeClass(
$attributeClass,
$annotationProperty,
);
}
}
}
public function getTag(): string
{
return $this->tag;
}
/**
* @return AnnotationPropertyToAttributeClass[]
*/
public function getAnnotationPropertiesToAttributeClasses(): array
{
return $this->annotationPropertiesToAttributeClasses;
}
public function getAttributeClass(): string
{
return $this->tag;
}
public function shouldRemoveOriginal(): bool
{
return $this->removeOriginal;
}
public function hasExplicitParameters(): bool
{
foreach ($this->annotationPropertiesToAttributeClasses as $annotationPropertyToAttributeClass) {
if (is_string($annotationPropertyToAttributeClass->getAnnotationProperty())) {
return true;
}
}
return false;
}
}