@@ -81,12 +81,12 @@ class Interpreter
81
81
/**
82
82
* Split multiple messages and process
83
83
*
84
- * @param string $xmlMsg Path to XML Message representation
85
- * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml
86
- * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml
87
- * @param array $messageTextConf Personalisation of error messages
84
+ * @param string $xmlMsg Path to XML Message representation
85
+ * @param array $xmlSeg Segments processed by EDI\Analyser::loadSegmentsXml
86
+ * @param array $xmlSvc Service segments processed by EDI\Analyser::loadSegmentsXml
87
+ * @param null| array $messageTextConf Personalisation of error messages
88
88
*/
89
- public function __construct ($ xmlMsg , $ xmlSeg , $ xmlSvc , $ messageTextConf = null )
89
+ public function __construct (string $ xmlMsg , array $ xmlSeg , array $ xmlSvc , array $ messageTextConf = null )
90
90
{
91
91
$ this ->xmlMsg = \simplexml_load_file ($ xmlMsg );
92
92
$ this ->xmlSeg = $ xmlSeg ;
@@ -108,7 +108,7 @@ public function __construct($xmlMsg, $xmlSeg, $xmlSvc, $messageTextConf = null)
108
108
*
109
109
* @return void
110
110
*/
111
- public function setMessageTextConf ($ messageTextConf )
111
+ public function setMessageTextConf (array $ messageTextConf )
112
112
{
113
113
$ this ->messageTextConf = \array_replace ($ this ->messageTextConf , $ messageTextConf );
114
114
}
@@ -120,7 +120,7 @@ public function setMessageTextConf($messageTextConf)
120
120
*
121
121
* @return void
122
122
*/
123
- public function setSegmentTemplates ($ segmentTemplates )
123
+ public function setSegmentTemplates (array $ segmentTemplates )
124
124
{
125
125
$ this ->segmentTemplates = $ segmentTemplates ;
126
126
}
@@ -132,7 +132,7 @@ public function setSegmentTemplates($segmentTemplates)
132
132
*
133
133
* @return void
134
134
*/
135
- public function setGroupTemplates ($ groupTemplates )
135
+ public function setGroupTemplates (array $ groupTemplates )
136
136
{
137
137
$ this ->groupTemplates = $ groupTemplates ;
138
138
}
@@ -156,7 +156,7 @@ public function setComparisonFunction(callable $func)
156
156
*
157
157
* @return array
158
158
*/
159
- public function prepare ($ parsed ): array
159
+ public function prepare (array $ parsed ): array
160
160
{
161
161
$ this ->msgs = $ this ->splitMessages ($ parsed , $ this ->errors );
162
162
$ groups = [];
@@ -267,7 +267,7 @@ private function splitMessages(&$parsed, &$errors): array
267
267
*
268
268
* @return array
269
269
*/
270
- private function loopMessage (&$ message , $ xml , &$ errors ): array
270
+ private function loopMessage (array &$ message , \ SimpleXMLElement $ xml , array &$ errors ): array
271
271
{
272
272
// init
273
273
$ groupedEdi = [];
@@ -301,7 +301,7 @@ private function loopMessage(&$message, $xml, &$errors): array
301
301
*
302
302
* @return void
303
303
*/
304
- private function processXmlGroup ($ elm , &$ message , &$ segmentIdx , &$ array , &$ errors )
304
+ private function processXmlGroup (\ SimpleXMLElement $ elm , array &$ message , int &$ segmentIdx , array &$ array , array &$ errors )
305
305
{
306
306
// init
307
307
$ groupVisited = false ;
@@ -345,7 +345,7 @@ private function processXmlGroup($elm, &$message, &$segmentIdx, &$array, &$error
345
345
346
346
}
347
347
348
- if (\count ($ newGroup ) == 0 ) {
348
+ if (\count ($ newGroup ) === 0 ) {
349
349
return ;
350
350
}
351
351
@@ -363,9 +363,11 @@ private function processXmlGroup($elm, &$message, &$segmentIdx, &$array, &$error
363
363
*
364
364
* @return void
365
365
*/
366
- private function processXmlSegment ($ elm , &$ message , &$ segmentIdx , &$ array , &$ errors )
366
+ private function processXmlSegment (\ SimpleXMLElement $ elm , array &$ message , int &$ segmentIdx , array &$ array , array &$ errors )
367
367
{
368
+ // init
368
369
$ segmentVisited = false ;
370
+
369
371
for ($ i = 0 ; $ i < $ elm ['maxrepeat ' ]; $ i ++) {
370
372
371
373
if (\call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx ], $ elm )) {
@@ -412,7 +414,7 @@ private function processXmlSegment($elm, &$message, &$segmentIdx, &$array, &$err
412
414
*
413
415
* @return void
414
416
*/
415
- private function doAddArray (&$ array , &$ jsonMessage )
417
+ private function doAddArray (array &$ array , array &$ jsonMessage )
416
418
{
417
419
if (isset ($ array [$ jsonMessage ['key ' ]])) {
418
420
if (
@@ -435,12 +437,12 @@ private function doAddArray(&$array, &$jsonMessage)
435
437
*
436
438
* @param array $segment
437
439
* @param array $xmlMap
438
- * @param int $segmentIdx
440
+ * @param null| int $segmentIdx
439
441
* @param null|array $errors
440
442
*
441
443
* @return array
442
444
*/
443
- private function processSegment (&$ segment , &$ xmlMap , $ segmentIdx , &$ errors = null ): array
445
+ private function processSegment (array &$ segment , array &$ xmlMap , $ segmentIdx , array &$ errors = null ): array
444
446
{
445
447
$ id = $ segment [0 ];
446
448
@@ -508,7 +510,7 @@ private function processSegment(&$segment, &$xmlMap, $segmentIdx, &$errors = nul
508
510
$ jsoncomposite = $ detail ;
509
511
}
510
512
511
- if (array_key_exists ($ d_desc_attr ['name ' ], $ jsonelements )) {
513
+ if (\ array_key_exists ($ d_desc_attr ['name ' ], $ jsonelements )) {
512
514
$ jsonelements [$ d_desc_attr ['name ' ] . $ n ] = $ jsoncomposite ;
513
515
} else {
514
516
$ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
@@ -535,9 +537,11 @@ private function processSegment(&$segment, &$xmlMap, $segmentIdx, &$errors = nul
535
537
*
536
538
* @return array
537
539
*/
538
- private function processService (&$ segments ): array
540
+ private function processService (array &$ segments ): array
539
541
{
542
+ // init
540
543
$ processed = [];
544
+
541
545
foreach ($ segments as &$ seg ) {
542
546
$ jsonsegment = $ this ->processSegment ($ seg , $ this ->xmlSvc , null );
543
547
$ processed [$ jsonsegment ['key ' ]] = $ jsonsegment ['value ' ];
@@ -553,7 +557,7 @@ private function processService(&$segments): array
553
557
*
554
558
* @return false|string
555
559
*/
556
- public function getJson ($ pretty = false )
560
+ public function getJson (bool $ pretty = false )
557
561
{
558
562
if ($ pretty ) {
559
563
return \json_encode ($ this ->ediGroups , JSON_PRETTY_PRINT );
@@ -593,7 +597,7 @@ public function getServiceSegments()
593
597
*
594
598
* @return false|string
595
599
*/
596
- public function getJsonServiceSegments ($ pretty = false )
600
+ public function getJsonServiceSegments (bool $ pretty = false )
597
601
{
598
602
if ($ pretty ) {
599
603
return \json_encode ($ this ->serviceSeg , JSON_PRETTY_PRINT );
0 commit comments