99use Qameta \Allure \Exception \InvalidMethodNameException ;
1010use Qameta \Allure \Model ;
1111use Qameta \Allure \Model \ModelProviderInterface ;
12+ use Qameta \Allure \Setup \LinkTemplateCollection ;
13+ use Qameta \Allure \Setup \LinkTemplateCollectionInterface ;
1214use ReflectionClass ;
1315use ReflectionException ;
1416use ReflectionFunction ;
1820use function array_merge ;
1921use function is_string ;
2022
21- class AttributeParser implements ModelProviderInterface
23+ final class AttributeParser implements ModelProviderInterface
2224{
25+ use Model \ModelProviderTrait;
2326
2427 private ?string $ displayName = null ;
2528
@@ -43,12 +46,12 @@ class AttributeParser implements ModelProviderInterface
4346 private array $ parameters = [];
4447
4548 /**
46- * @param array<AttributeInterface> $attributes
47- * @param array<string, LinkTemplateInterface> $linkTemplates
49+ * @param array<AttributeInterface> $attributes
50+ * @param LinkTemplateCollectionInterface $linkTemplates
4851 */
4952 public function __construct (
5053 array $ attributes ,
51- private array $ linkTemplates = [] ,
54+ private LinkTemplateCollectionInterface $ linkTemplates ,
5255 ) {
5356 $ this ->processAnnotations (...$ attributes );
5457 }
@@ -57,15 +60,15 @@ public function __construct(
5760 * @param class-string|object|null $classOrObject
5861 * @param callable-string|Closure|null $methodOrFunction
5962 * @param string|null $property
60- * @param array<string, LinkTemplateInterface> $linkTemplates
63+ * @param LinkTemplateCollectionInterface|null $linkTemplates
6164 * @return list<ModelProviderInterface>
6265 * @throws ReflectionException
6366 */
6467 public static function createForChain (
6568 string |object |null $ classOrObject ,
6669 string |Closure |null $ methodOrFunction = null ,
6770 ?string $ property = null ,
68- array $ linkTemplates = [] ,
71+ ? LinkTemplateCollectionInterface $ linkTemplates = null ,
6972 ): array {
7073 $ reader = new LegacyAttributeReader (
7174 new AnnotationReader (),
@@ -96,7 +99,7 @@ public static function createForChain(
9699 return [
97100 new self (
98101 array_merge (...$ annotations ),
99- $ linkTemplates ,
102+ $ linkTemplates ?? new LinkTemplateCollection () ,
100103 )
101104 ];
102105 }
@@ -128,22 +131,15 @@ private function processAnnotations(AttributeInterface ...$attributes): void
128131
129132 private function createLink (LinkInterface $ link ): Model \Link
130133 {
131- $ linkType = $ link ->getType ();
134+ $ linkType = Model \LinkType:: fromOptionalString ( $ link ->getType () );
132135
133136 return new Model \Link (
134137 name: $ link ->getName (),
135- url: $ link ->getUrl () ?? $ this ->getLinkUrl ( $ link ->getName (), $ linkType ),
136- type: Model \LinkType:: fromOptionalString ( $ linkType) ,
138+ url: $ link ->getUrl () ?? $ this ->linkTemplates -> get ( $ linkType )?->buildUrl( $ link ->getName ()),
139+ type: $ linkType ,
137140 );
138141 }
139142
140- private function getLinkUrl (?string $ name , ?string $ type ): ?string
141- {
142- return isset ($ type , $ this ->linkTemplates [$ type ])
143- ? $ this ->linkTemplates [$ type ]->buildUrl ($ name )
144- : $ name ;
145- }
146-
147143 /**
148144 * @return list<Model\Link>
149145 */
@@ -186,14 +182,6 @@ public function getParameters(): array
186182 return $ this ->parameters ;
187183 }
188184
189- /**
190- * @deprecated Please use {@see getDisplayName()} method.
191- */
192- public function getTitle (): ?string
193- {
194- return $ this ->getDisplayName ();
195- }
196-
197185 public function getDisplayName (): ?string
198186 {
199187 return $ this ->displayName ;
0 commit comments