44
55namespace Kiboko \Component \Satellite \Plugin \Filtering \Builder ;
66
7- use Kiboko \Component \Bucket \RejectionResultBucket ;
8- use Kiboko \Component \Bucket \RejectionWithReasonResultBucket ;
9- use PhpParser \Builder ;
107use PhpParser \Node ;
118
12- final class ExclusionsBuilder implements Builder
9+ final class ExclusionsBuilder
1310{
1411 /** @var list<list<Node\Expr>> */
1512 private array $ exclusions = [];
1613
17- public function withCondition (Node \Expr $ condition , ?Node \Expr $ reason = null ): self
14+ public function withCondition (Node \Expr $ condition , ?Node \Expr $ reason): self
1815 {
1916 $ this ->exclusions [] = [
2017 'condition ' => $ condition ,
@@ -24,11 +21,10 @@ public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):s
2421 return $ this ;
2522 }
2623
27- public function getNode (): Node
24+ public function build (): \ Generator
2825 {
29- $ statements = [];
3026 foreach ($ this ->exclusions as $ exclusion ) {
31- $ statements [] = new Node \Stmt \If_ (
27+ yield new Node \Stmt \If_ (
3228 $ exclusion ['condition ' ],
3329 [
3430 'stmts ' => [
@@ -37,13 +33,15 @@ public function getNode(): Node
3733 new Node \Expr \Variable ('input ' ),
3834 new Node \Expr \Yield_ (
3935 new Node \Expr \New_ (
40- \array_key_exists ( ' reason ' , $ exclusion ) ? new Node \Name \FullyQualified (RejectionWithReasonResultBucket::class) : new Node \ Name \ FullyQualified ( RejectionResultBucket::class ),
36+ new Node \Name \FullyQualified (' Kiboko \\ Component \\ Bucket \\ RejectionResultBucket ' ),
4137 [
42- new Node \Arg (new Node \Expr \Variable ('input ' )),
43- \array_key_exists ('reason ' , $ exclusion ) ? new Node \Arg ($ exclusion ['reason ' ]) : new Node \Arg (
44- new Node \Expr \ConstFetch (
45- new Node \Name (null )
46- ),
38+ new Node \Arg (
39+ value: $ exclusion ['reason ' ],
40+ name: new Node \Identifier ('reason ' )
41+ ),
42+ new Node \Arg (
43+ value: new Node \Expr \Variable ('input ' ),
44+ name: new Node \Identifier ('values ' )
4745 ),
4846 ]
4947 ),
@@ -55,7 +53,5 @@ public function getNode(): Node
5553 ]
5654 );
5755 }
58-
59- return new Node ;
6056 }
6157}
0 commit comments