4
4
5
5
namespace Kiboko \Component \Satellite \Plugin \Filtering \Builder ;
6
6
7
- use Kiboko \Component \Bucket \RejectionResultBucket ;
8
- use Kiboko \Component \Bucket \RejectionWithReasonResultBucket ;
9
- use PhpParser \Builder ;
10
7
use PhpParser \Node ;
11
8
12
- final class ExclusionsBuilder implements Builder
9
+ final class ExclusionsBuilder
13
10
{
14
11
/** @var list<list<Node\Expr>> */
15
12
private array $ exclusions = [];
16
13
17
- public function withCondition (Node \Expr $ condition , ?Node \Expr $ reason = null ): self
14
+ public function withCondition (Node \Expr $ condition , ?Node \Expr $ reason): self
18
15
{
19
16
$ this ->exclusions [] = [
20
17
'condition ' => $ condition ,
@@ -24,11 +21,10 @@ public function withCondition(Node\Expr $condition, ?Node\Expr $reason = null):s
24
21
return $ this ;
25
22
}
26
23
27
- public function getNode (): Node
24
+ public function build (): \ Generator
28
25
{
29
- $ statements = [];
30
26
foreach ($ this ->exclusions as $ exclusion ) {
31
- $ statements [] = new Node \Stmt \If_ (
27
+ yield new Node \Stmt \If_ (
32
28
$ exclusion ['condition ' ],
33
29
[
34
30
'stmts ' => [
@@ -37,13 +33,15 @@ public function getNode(): Node
37
33
new Node \Expr \Variable ('input ' ),
38
34
new Node \Expr \Yield_ (
39
35
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 ' ),
41
37
[
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 ' )
47
45
),
48
46
]
49
47
),
@@ -55,7 +53,5 @@ public function getNode(): Node
55
53
]
56
54
);
57
55
}
58
-
59
- return new Node ;
60
56
}
61
57
}
0 commit comments