44
55namespace Flow \ETL \Row ;
66
7+ use function Flow \ETL \DSL \lit ;
78use Flow \ETL \Exception \InvalidArgumentException ;
89use Flow \ETL \Row ;
10+ use Flow \ETL \Row \Reference \Expression ;
911use Flow \ETL \Row \Reference \Expression \Contains ;
1012use Flow \ETL \Row \Reference \Expression \Divide ;
1113use Flow \ETL \Row \Reference \Expression \EndsWith ;
3436/**
3537 * @implements Reference<array{entry: string, alias: ?string, expressions: Expressions}>
3638 */
37- final class EntryReference implements Reference
39+ final class EntryReference implements Expression, Reference
3840{
3941 private ?string $ alias = null ;
4042
@@ -91,9 +93,9 @@ public function asc() : self
9193 return $ this ;
9294 }
9395
94- public function contains (self | string |Literal $ needle ) : self
96+ public function contains (string |Expression $ needle ) : self
9597 {
96- $ this ->expressions ->add (new Contains ($ this , $ needle instanceof Literal ? $ needle : self ::init ($ needle )));
98+ $ this ->expressions ->add (new Contains ($ this , \is_string ( $ needle) ? self ::init ($ needle ) : $ needle ));
9799
98100 return $ this ;
99101 }
@@ -105,23 +107,23 @@ public function desc() : self
105107 return $ this ;
106108 }
107109
108- public function divide (self | string |Literal $ ref ) : self
110+ public function divide (string |Expression $ ref ) : self
109111 {
110- $ this ->expressions = $ this ->expressions ->add (new Divide ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
112+ $ this ->expressions = $ this ->expressions ->add (new Divide ($ this , \is_string ( $ ref)? self ::init ($ ref ) : $ ref ));
111113
112114 return $ this ;
113115 }
114116
115- public function endsWith (self | string |Literal $ needle ) : self
117+ public function endsWith (string |Expression $ needle ) : self
116118 {
117- $ this ->expressions ->add (new EndsWith ($ this , $ needle instanceof Literal ? $ needle : self ::init ($ needle )));
119+ $ this ->expressions ->add (new EndsWith ($ this , \is_string ( $ needle) ? self ::init ($ needle ) : $ needle ));
118120
119121 return $ this ;
120122 }
121123
122- public function equals (self | string |Literal $ ref ) : self
124+ public function equals (string |Expression $ ref ) : self
123125 {
124- $ this ->expressions = $ this ->expressions ->add (new Equals ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
126+ $ this ->expressions = $ this ->expressions ->add (new Equals ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
125127
126128 return $ this ;
127129 }
@@ -136,16 +138,16 @@ public function expressions() : Expressions
136138 return $ this ->expressions ;
137139 }
138140
139- public function greaterThan (self | string |Literal $ ref ) : self
141+ public function greaterThan (string |Expression $ ref ) : self
140142 {
141- $ this ->expressions = $ this ->expressions ->add (new GreaterThan ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
143+ $ this ->expressions = $ this ->expressions ->add (new GreaterThan ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
142144
143145 return $ this ;
144146 }
145147
146- public function greaterThanEqual (self | string |Literal $ ref ) : self
148+ public function greaterThanEqual (string |Expression $ ref ) : self
147149 {
148- $ this ->expressions = $ this ->expressions ->add (new GreaterThanEqual ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
150+ $ this ->expressions = $ this ->expressions ->add (new GreaterThanEqual ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
149151
150152 return $ this ;
151153 }
@@ -160,9 +162,18 @@ public function is(Reference $ref) : bool
160162 return $ this ->name () === $ ref ->name ();
161163 }
162164
163- public function isIn ( self | string | Literal $ haystack ) : self
165+ public function isEven ( ) : self
164166 {
165- $ this ->expressions ->add (new IsIn ($ haystack instanceof Literal ? $ haystack : self ::init ($ haystack ), $ this ));
167+ $ this ->expressions = $ this ->expressions
168+ ->add (new Mod ($ this , lit (2 )))
169+ ->add (new Equals ($ this , lit (0 )));
170+
171+ return $ this ;
172+ }
173+
174+ public function isIn (string |Expression $ haystack ) : self
175+ {
176+ $ this ->expressions ->add (new IsIn (\is_string ($ haystack ) ? self ::init ($ haystack ) : $ haystack , $ this ));
166177
167178 return $ this ;
168179 }
@@ -181,6 +192,15 @@ public function isNull() : self
181192 return $ this ;
182193 }
183194
195+ public function isOdd () : self
196+ {
197+ $ this ->expressions = $ this ->expressions
198+ ->add (new Mod ($ this , lit (2 )))
199+ ->add (new NotEquals ($ this , lit (0 )));
200+
201+ return $ this ;
202+ }
203+
184204 /**
185205 * @param class-string<Entry> ...$entryClass
186206 */
@@ -195,16 +215,16 @@ public function isType(string ...$entryClass) : self
195215 return $ this ;
196216 }
197217
198- public function lessThan (self | string |Literal $ ref ) : self
218+ public function lessThan (string |Expression $ ref ) : self
199219 {
200- $ this ->expressions = $ this ->expressions ->add (new LessThan ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
220+ $ this ->expressions = $ this ->expressions ->add (new LessThan ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
201221
202222 return $ this ;
203223 }
204224
205- public function lessThanEqual (self | string |Literal $ ref ) : self
225+ public function lessThanEqual (string |Expression $ ref ) : self
206226 {
207- $ this ->expressions = $ this ->expressions ->add (new LessThanEqual ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
227+ $ this ->expressions = $ this ->expressions ->add (new LessThanEqual ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
208228
209229 return $ this ;
210230 }
@@ -216,23 +236,23 @@ public function literal(mixed $value) : self
216236 return $ this ;
217237 }
218238
219- public function minus (self | string |Literal $ ref ) : self
239+ public function minus (string |Expression $ ref ) : self
220240 {
221- $ this ->expressions = $ this ->expressions ->add (new Minus ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
241+ $ this ->expressions = $ this ->expressions ->add (new Minus ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
222242
223243 return $ this ;
224244 }
225245
226- public function mod (self | string |Literal $ ref ) : self
246+ public function mod (string |Expression $ ref ) : self
227247 {
228- $ this ->expressions = $ this ->expressions ->add (new Mod ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
248+ $ this ->expressions = $ this ->expressions ->add (new Mod ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
229249
230250 return $ this ;
231251 }
232252
233- public function multiply (self | string |Literal $ ref ) : self
253+ public function multiply (string |Expression $ ref ) : self
234254 {
235- $ this ->expressions = $ this ->expressions ->add (new Multiply ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
255+ $ this ->expressions = $ this ->expressions ->add (new Multiply ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
236256
237257 return $ this ;
238258 }
@@ -242,37 +262,37 @@ public function name() : string
242262 return $ this ->alias ?? $ this ->entry ;
243263 }
244264
245- public function notEquals (self | string |Literal $ ref ) : self
265+ public function notEquals (string |Expression $ ref ) : self
246266 {
247- $ this ->expressions = $ this ->expressions ->add (new NotEquals ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
267+ $ this ->expressions = $ this ->expressions ->add (new NotEquals ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
248268
249269 return $ this ;
250270 }
251271
252- public function notSame (self | string |Literal $ ref ) : self
272+ public function notSame (string |Expression $ ref ) : self
253273 {
254- $ this ->expressions = $ this ->expressions ->add (new NotSame ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
274+ $ this ->expressions = $ this ->expressions ->add (new NotSame ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
255275
256276 return $ this ;
257277 }
258278
259- public function plus (self | string |Literal $ ref ) : self
279+ public function plus (string |Expression $ ref ) : self
260280 {
261- $ this ->expressions = $ this ->expressions ->add (new Plus ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
281+ $ this ->expressions = $ this ->expressions ->add (new Plus ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
262282
263283 return $ this ;
264284 }
265285
266- public function power (self | string |Literal $ ref ) : self
286+ public function power (string |Expression $ ref ) : self
267287 {
268- $ this ->expressions = $ this ->expressions ->add (new Power ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
288+ $ this ->expressions = $ this ->expressions ->add (new Power ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
269289
270290 return $ this ;
271291 }
272292
273- public function same (self | string |Literal $ ref ) : self
293+ public function same (string |Expression $ ref ) : self
274294 {
275- $ this ->expressions = $ this ->expressions ->add (new Same ($ this , $ ref instanceof Literal ? $ ref : self ::init ($ ref )));
295+ $ this ->expressions = $ this ->expressions ->add (new Same ($ this , \is_string ( $ ref) ? self ::init ($ ref ) : $ ref ));
276296
277297 return $ this ;
278298 }
@@ -282,9 +302,9 @@ public function sort() : SortOrder
282302 return $ this ->sort ;
283303 }
284304
285- public function startsWith (self | string |Literal $ needle ) : self
305+ public function startsWith (string |Expression $ needle ) : self
286306 {
287- $ this ->expressions ->add (new StartsWith ($ this , $ needle instanceof Literal ? $ needle : self ::init ($ needle )));
307+ $ this ->expressions ->add (new StartsWith ($ this , \is_string ( $ needle) ? self ::init ($ needle ) : $ needle ));
288308
289309 return $ this ;
290310 }
0 commit comments