9
9
use PhpParser \Builder ;
10
10
use PhpParser \Node ;
11
11
12
- final readonly class Transformer implements StepBuilderInterface
12
+ final class Transformer implements StepBuilderInterface
13
13
{
14
- public function __construct (private Builder |Node $ mapper )
14
+ private ?Node \Expr $ logger = null ;
15
+
16
+ public function __construct (private readonly Builder |Node $ mapper )
15
17
{
16
18
}
17
19
18
20
public function withLogger (Node \Expr $ logger ): self
19
21
{
22
+ $ this ->logger = $ logger ;
23
+
20
24
return $ this ;
21
25
}
22
26
@@ -54,6 +58,15 @@ class: new Node\Stmt\Class_(
54
58
),
55
59
flags: Node \Stmt \Class_::MODIFIER_PRIVATE
56
60
),
61
+ new Node \Param (
62
+ var: new Node \Expr \Variable (
63
+ name: 'logger '
64
+ ),
65
+ type: new Node \Name \FullyQualified (
66
+ name: \Psr \Log \LoggerInterface::class
67
+ ),
68
+ flags: Node \Stmt \Class_::MODIFIER_PUBLIC ,
69
+ ),
57
70
],
58
71
],
59
72
),
@@ -64,45 +77,108 @@ class: new Node\Stmt\Class_(
64
77
'stmts ' => [
65
78
new Node \Stmt \Expression (
66
79
new Node \Expr \Assign (
67
- var: new Node \Expr \Variable ('line ' ),
80
+ var: new Node \Expr \Variable ('input ' ),
68
81
expr: new Node \Expr \Yield_ (null )
69
82
),
70
83
),
71
- new Node \Stmt \Do_ (
72
- cond: new Node \Expr \Assign (
73
- var: new Node \Expr \Variable ('line ' ),
74
- expr: new Node \Expr \Yield_ (
75
- new Node \Expr \New_ (
76
- class: new Node \Name \FullyQualified (
77
- \Kiboko \Component \Bucket \AcceptanceResultBucket::class
78
- ),
79
- args: [
80
- new Node \Arg (
81
- new Node \Expr \Variable ('line ' ),
82
- ),
83
- ],
84
- )
84
+ new Node \Stmt \While_ (
85
+ cond: new Node \Expr \BinaryOp \NotIdentical (
86
+ left: new Node \Expr \Variable ('input ' ),
87
+ right: new Node \Expr \ConstFetch (
88
+ new Node \Name ('null ' )
85
89
)
86
90
),
87
91
stmts: [
88
- new Node \Stmt \Expression (
89
- new Node \Expr \Assign (
90
- var: new Node \Expr \Variable ('line ' ),
91
- expr: new Node \Expr \FuncCall (
92
- name: new Node \Expr \PropertyFetch (
93
- var: new Node \Expr \Variable ('this ' ),
94
- name: new Node \Identifier ('mapper ' ),
92
+ new Node \Stmt \TryCatch (
93
+ stmts: [
94
+ new Node \Stmt \Expression (
95
+ new Node \Expr \Assign (
96
+ var: new Node \Expr \Variable ('line ' ),
97
+ expr: new Node \Expr \FuncCall (
98
+ name: new Node \Expr \PropertyFetch (
99
+ var: new Node \Expr \Variable ('this ' ),
100
+ name: new Node \Identifier ('mapper ' ),
101
+ ),
102
+ args: [
103
+ new Node \Arg (
104
+ value: new Node \Expr \Variable ('input ' )
105
+ ),
106
+ new Node \Arg (
107
+ value: new Node \Expr \Variable ('input ' )
108
+ ),
109
+ ]
110
+ ),
95
111
),
96
- args: [
97
- new Node \Arg (
98
- value: new Node \Expr \Variable ('line ' )
112
+ ),
113
+ ],
114
+ catches: [
115
+ new Node \Stmt \Catch_ (
116
+ types: [
117
+ new Node \Name \FullyQualified (\Kiboko \Contract \Pipeline \RejectedItemException::class),
118
+ ],
119
+ var: new Node \Expr \Variable ('exception ' ),
120
+ stmts: [
121
+ new Node \Stmt \Expression (
122
+ new Node \Expr \MethodCall (
123
+ var: new Node \Expr \PropertyFetch (
124
+ var: new Node \Expr \Variable ('this ' ),
125
+ name: new Node \Identifier ('logger ' ),
126
+ ),
127
+ name: new Node \Name ('error ' ),
128
+ args: [
129
+ new Node \Arg (
130
+ new Node \Expr \MethodCall (
131
+ var: new Node \Expr \Variable ('exception ' ),
132
+ name: new Node \Identifier ('getMessage ' )
133
+ )
134
+ ),
135
+ new Node \Expr \Array_ ([
136
+ new Node \Expr \ArrayItem (
137
+ value: new Node \Expr \Variable ('input ' ),
138
+ key: new Node \Scalar \String_ ('input ' )
139
+ ),
140
+ ]),
141
+ ]
142
+ )
99
143
),
100
- new Node \Arg (
101
- value: new Node \Expr \Variable ('line ' )
144
+ new Node \Stmt \Expression (
145
+ new Node \Expr \Assign (
146
+ var: new Node \Expr \Variable ('input ' ),
147
+ expr: new Node \Expr \Yield_ (
148
+ new Node \Expr \New_ (
149
+ class: new Node \Name \FullyQualified (
150
+ \Kiboko \Component \Bucket \RejectionResultBucket::class
151
+ ),
152
+ args: [
153
+ new Node \Arg (
154
+ new Node \Expr \Variable ('input ' ),
155
+ ),
156
+ ],
157
+ )
158
+ )
159
+ ),
102
160
),
161
+ new Node \Stmt \Continue_ (),
103
162
]
104
163
),
105
- ),
164
+ ]
165
+ ),
166
+ new Node \Stmt \Expression (
167
+ new Node \Expr \Assign (
168
+ var: new Node \Expr \Variable ('input ' ),
169
+ expr: new Node \Expr \Yield_ (
170
+ new Node \Expr \New_ (
171
+ class: new Node \Name \FullyQualified (
172
+ \Kiboko \Component \Bucket \AcceptanceResultBucket::class
173
+ ),
174
+ args: [
175
+ new Node \Arg (
176
+ new Node \Expr \Variable ('line ' ),
177
+ ),
178
+ ],
179
+ )
180
+ )
181
+ )
106
182
),
107
183
],
108
184
),
@@ -114,7 +190,7 @@ class: new Node\Name\FullyQualified(
114
190
),
115
191
args: [
116
192
new Node \Arg (
117
- new Node \Expr \Variable ('line ' ),
193
+ new Node \Expr \Variable ('input ' ),
118
194
),
119
195
],
120
196
),
@@ -131,6 +207,9 @@ class: new Node\Name\FullyQualified(
131
207
new Node \Arg (
132
208
$ this ->mapper instanceof Builder ? $ this ->mapper ->getNode () : $ this ->mapper ,
133
209
),
210
+ new Node \Arg (
211
+ $ this ->logger ?? new Node \Expr \New_ (new Node \Name \FullyQualified (\Psr \Log \NullLogger::class))
212
+ ),
134
213
],
135
214
);
136
215
}
0 commit comments