@@ -195,71 +195,55 @@ public function readEdiDataValueReq($filter, int $l1, $l2 = false)
195
195
/**
196
196
* read data value from parsed EDI data
197
197
*
198
- * @param array<mixed> |string $filter 'AGR' - segment code
199
- * or ['AGR',['1'=>'BB']], where AGR segment code and first element equal 'BB'
200
- * or ['AGR',['1.0'=>'BB']], where AGR segment code and first element zero subelement
201
- * equal 'BB'
202
- * @param int $l1 first level item number (start by 1)
203
- * @param false|int $l2 second level item number (start by 0)
204
- * @param bool $required if required, but no exist, register error
198
+ * @param array|string $filter 'AGR' - segment code
199
+ * or ['AGR',['1'=>'BB']], where AGR segment code and first element equal 'BB'
200
+ * or ['AGR',['1.0'=>'BB']], where AGR segment code and first element zero subelement
201
+ * equal 'BB'
202
+ * @param int $l1 first level item number (start by 1)
203
+ * @param false|int $l2 second level item number (start by 0)
204
+ * @param bool $required if required, but no exist, register error
205
205
*
206
206
* @return string|null
207
207
*/
208
208
public function readEdiDataValue ($ filter , int $ l1 , $ l2 = false , bool $ required = false )
209
209
{
210
- // interpret filter parameters
210
+ $ segment = false ;
211
+ $ segment_count = 0 ;
212
+ $ segment_name = $ filter ;
213
+ $ filter_elements = false ;
211
214
if (\is_array ($ filter )) {
212
215
$ segment_name = $ filter [0 ];
213
216
$ filter_elements = $ filter [1 ];
214
- } else {
215
- $ segment_name = $ filter ;
216
- $ filter_elements = false ;
217
217
}
218
218
219
- // init
220
- $ segment = false ;
221
- $ segment_count = 0 ;
222
-
223
- // search segment, who conform to filter
219
+ // search segments which conform to filter
224
220
foreach ($ this ->parsedfile as $ edi_row ) {
225
221
if ($ edi_row [0 ] == $ segment_name ) {
226
222
if ($ filter_elements ) {
227
- $ filter_ok = false ;
228
223
foreach ($ filter_elements as $ el_id => $ el_value ) {
224
+ $ filter_ok = false ;
229
225
$ f_el_list = \explode ('. ' , (string ) $ el_id );
230
226
if (\count ($ f_el_list ) === 1 ) {
231
- if (
232
- isset ($ edi_row [$ el_id ])
233
- &&
234
- $ edi_row [$ el_id ] == $ el_value
235
- ) {
227
+ if (isset ($ edi_row [$ el_id ]) && $ edi_row [$ el_id ] == $ el_value ) {
236
228
$ filter_ok = true ;
237
-
238
- break ;
239
229
}
240
230
} elseif (
241
231
isset ($ edi_row [$ f_el_list [0 ]])
242
- &&
243
- (
232
+ && (
244
233
(
245
234
isset ($ edi_row [$ f_el_list [0 ]][$ f_el_list [1 ]])
246
- &&
247
- \is_array ($ edi_row [$ f_el_list [0 ]])
248
- &&
249
- $ edi_row [$ f_el_list [0 ]][$ f_el_list [1 ]] == $ el_value
250
- )
251
- ||
252
- (
235
+ && \is_array ($ edi_row [$ f_el_list [0 ]])
236
+ && $ edi_row [$ f_el_list [0 ]][$ f_el_list [1 ]] == $ el_value
237
+ ) || (
253
238
isset ($ edi_row [$ f_el_list [0 ]])
254
- &&
255
- \is_string ($ edi_row [$ f_el_list [0 ]])
256
- &&
257
- $ edi_row [$ f_el_list [0 ]] == $ el_value
239
+ && \is_string ($ edi_row [$ f_el_list [0 ]])
240
+ && $ edi_row [$ f_el_list [0 ]] == $ el_value
258
241
)
259
242
)
260
243
) {
261
244
$ filter_ok = true ;
262
-
245
+ }
246
+ if ($ filter_ok === false ) {
263
247
break ;
264
248
}
265
249
}
@@ -273,7 +257,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required =
273
257
}
274
258
}
275
259
276
- // no found segment
260
+ // no segment found
277
261
if (!$ segment ) {
278
262
if ($ required ) {
279
263
$ this ->errors [] = 'Segment " ' . $ segment_name . '" no exist ' ;
@@ -282,7 +266,7 @@ public function readEdiDataValue($filter, int $l1, $l2 = false, bool $required =
282
266
return null ;
283
267
}
284
268
285
- // found more one segment - error
269
+ // found more than one segment - error
286
270
if ($ segment_count > 1 ) {
287
271
$ this ->errors [] = 'Segment " ' . $ segment_name . '" is ambiguous ' ;
288
272
0 commit comments