@@ -12,6 +12,7 @@ final class Extractor implements StepBuilderInterface
1212{
1313 private ?Node \Expr $ logger = null ;
1414 private ?Node \Expr $ client = null ;
15+ private string $ apiType ;
1516
1617 public function __construct (private readonly Builder $ capacity )
1718 {
@@ -24,6 +25,13 @@ public function withClient(Node\Expr $client): self
2425 return $ this ;
2526 }
2627
28+ public function withApiType (string $ apiType ): self
29+ {
30+ $ this ->apiType = $ apiType ;
31+
32+ return $ this ;
33+ }
34+
2735 public function withLogger (Node \Expr $ logger ): self
2836 {
2937 $ this ->logger = $ logger ;
@@ -55,18 +63,7 @@ class: new Node\Stmt\Class_(
5563 name: new Node \Identifier (name: '__construct ' ),
5664 subNodes: [
5765 '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 (),
7067 ],
7168 ),
7269 new Node \Stmt \ClassMethod (
@@ -133,4 +130,26 @@ class: new Node\Stmt\Class_(
133130 ],
134131 );
135132 }
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+ }
136155}
0 commit comments