@@ -12,6 +12,7 @@ final class Extractor implements StepBuilderInterface
12
12
{
13
13
private ?Node \Expr $ logger = null ;
14
14
private ?Node \Expr $ client = null ;
15
+ private string $ apiType ;
15
16
16
17
public function __construct (private readonly Builder $ capacity )
17
18
{
@@ -24,6 +25,13 @@ public function withClient(Node\Expr $client): self
24
25
return $ this ;
25
26
}
26
27
28
+ public function withApiType (string $ apiType ): self
29
+ {
30
+ $ this ->apiType = $ apiType ;
31
+
32
+ return $ this ;
33
+ }
34
+
27
35
public function withLogger (Node \Expr $ logger ): self
28
36
{
29
37
$ this ->logger = $ logger ;
@@ -55,18 +63,7 @@ class: new Node\Stmt\Class_(
55
63
name: new Node \Identifier (name: '__construct ' ),
56
64
subNodes: [
57
65
'flags ' => Node \Stmt \Class_::MODIFIER_PUBLIC ,
58
- 'params ' => [
59
- new Node \Param (
60
- var: new Node \Expr \Variable ('client ' ),
61
- type: new Node \Name \FullyQualified (name: \Diglin \Sylius \ApiClient \SyliusLegacyClientInterface::class),
62
- flags: Node \Stmt \Class_::MODIFIER_PUBLIC ,
63
- ),
64
- new Node \Param (
65
- var: new Node \Expr \Variable ('logger ' ),
66
- type: new Node \Name \FullyQualified (name: \Psr \Log \LoggerInterface::class),
67
- flags: Node \Stmt \Class_::MODIFIER_PUBLIC ,
68
- ),
69
- ],
66
+ 'params ' => $ this ->getParamsNode (),
70
67
],
71
68
),
72
69
new Node \Stmt \ClassMethod (
@@ -133,4 +130,26 @@ class: new Node\Stmt\Class_(
133
130
],
134
131
);
135
132
}
133
+
134
+ public function getParamsNode (): array
135
+ {
136
+
137
+ $ className = match ($ this ->apiType ) {
138
+ Client::API_ADMIN_KEY => \Diglin \Sylius \ApiClient \SyliusAdminClientInterface::class,
139
+ Client::API_LEGACY_KEY => \Diglin \Sylius \ApiClient \SyliusLegacyClientInterface::class,
140
+ Client::API_SHOP_KEY => \Diglin \Sylius \ApiClient \SyliusShopClientInterface::class,
141
+ };
142
+ return [
143
+ new Node \Param (
144
+ var: new Node \Expr \Variable ('client ' ),
145
+ type: new Node \Name \FullyQualified (name: $ className ),
146
+ flags: Node \Stmt \Class_::MODIFIER_PRIVATE ,
147
+ ),
148
+ new Node \Param (
149
+ var: new Node \Expr \Variable ('logger ' ),
150
+ type: new Node \Name \FullyQualified (name: \Psr \Log \LoggerInterface::class),
151
+ flags: Node \Stmt \Class_::MODIFIER_PRIVATE ,
152
+ ),
153
+ ];
154
+ }
136
155
}
0 commit comments