@@ -81,12 +81,12 @@ class Interpreter
8181 /**
8282 * Split multiple messages and process
8383 *
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
8888 */
89- public function __construct ($ xmlMsg , $ xmlSeg , $ xmlSvc , $ messageTextConf = null )
89+ public function __construct (string $ xmlMsg , array $ xmlSeg , array $ xmlSvc , array $ messageTextConf = null )
9090 {
9191 $ this ->xmlMsg = \simplexml_load_file ($ xmlMsg );
9292 $ this ->xmlSeg = $ xmlSeg ;
@@ -108,7 +108,7 @@ public function __construct($xmlMsg, $xmlSeg, $xmlSvc, $messageTextConf = null)
108108 *
109109 * @return void
110110 */
111- public function setMessageTextConf ($ messageTextConf )
111+ public function setMessageTextConf (array $ messageTextConf )
112112 {
113113 $ this ->messageTextConf = \array_replace ($ this ->messageTextConf , $ messageTextConf );
114114 }
@@ -120,7 +120,7 @@ public function setMessageTextConf($messageTextConf)
120120 *
121121 * @return void
122122 */
123- public function setSegmentTemplates ($ segmentTemplates )
123+ public function setSegmentTemplates (array $ segmentTemplates )
124124 {
125125 $ this ->segmentTemplates = $ segmentTemplates ;
126126 }
@@ -132,7 +132,7 @@ public function setSegmentTemplates($segmentTemplates)
132132 *
133133 * @return void
134134 */
135- public function setGroupTemplates ($ groupTemplates )
135+ public function setGroupTemplates (array $ groupTemplates )
136136 {
137137 $ this ->groupTemplates = $ groupTemplates ;
138138 }
@@ -156,7 +156,7 @@ public function setComparisonFunction(callable $func)
156156 *
157157 * @return array
158158 */
159- public function prepare ($ parsed ): array
159+ public function prepare (array $ parsed ): array
160160 {
161161 $ this ->msgs = $ this ->splitMessages ($ parsed , $ this ->errors );
162162 $ groups = [];
@@ -267,7 +267,7 @@ private function splitMessages(&$parsed, &$errors): array
267267 *
268268 * @return array
269269 */
270- private function loopMessage (&$ message , $ xml , &$ errors ): array
270+ private function loopMessage (array &$ message , \ SimpleXMLElement $ xml , array &$ errors ): array
271271 {
272272 // init
273273 $ groupedEdi = [];
@@ -301,7 +301,7 @@ private function loopMessage(&$message, $xml, &$errors): array
301301 *
302302 * @return void
303303 */
304- private function processXmlGroup ($ elm , &$ message , &$ segmentIdx , &$ array , &$ errors )
304+ private function processXmlGroup (\ SimpleXMLElement $ elm , array &$ message , int &$ segmentIdx , array &$ array , array &$ errors )
305305 {
306306 // init
307307 $ groupVisited = false ;
@@ -345,7 +345,7 @@ private function processXmlGroup($elm, &$message, &$segmentIdx, &$array, &$error
345345
346346 }
347347
348- if (\count ($ newGroup ) == 0 ) {
348+ if (\count ($ newGroup ) === 0 ) {
349349 return ;
350350 }
351351
@@ -363,9 +363,11 @@ private function processXmlGroup($elm, &$message, &$segmentIdx, &$array, &$error
363363 *
364364 * @return void
365365 */
366- private function processXmlSegment ($ elm , &$ message , &$ segmentIdx , &$ array , &$ errors )
366+ private function processXmlSegment (\ SimpleXMLElement $ elm , array &$ message , int &$ segmentIdx , array &$ array , array &$ errors )
367367 {
368+ // init
368369 $ segmentVisited = false ;
370+
369371 for ($ i = 0 ; $ i < $ elm ['maxrepeat ' ]; $ i ++) {
370372
371373 if (\call_user_func ($ this ->comparisonFunction , $ message [$ segmentIdx ], $ elm )) {
@@ -412,7 +414,7 @@ private function processXmlSegment($elm, &$message, &$segmentIdx, &$array, &$err
412414 *
413415 * @return void
414416 */
415- private function doAddArray (&$ array , &$ jsonMessage )
417+ private function doAddArray (array &$ array , array &$ jsonMessage )
416418 {
417419 if (isset ($ array [$ jsonMessage ['key ' ]])) {
418420 if (
@@ -435,12 +437,12 @@ private function doAddArray(&$array, &$jsonMessage)
435437 *
436438 * @param array $segment
437439 * @param array $xmlMap
438- * @param int $segmentIdx
440+ * @param null| int $segmentIdx
439441 * @param null|array $errors
440442 *
441443 * @return array
442444 */
443- private function processSegment (&$ segment , &$ xmlMap , $ segmentIdx , &$ errors = null ): array
445+ private function processSegment (array &$ segment , array &$ xmlMap , $ segmentIdx , array &$ errors = null ): array
444446 {
445447 $ id = $ segment [0 ];
446448
@@ -508,7 +510,7 @@ private function processSegment(&$segment, &$xmlMap, $segmentIdx, &$errors = nul
508510 $ jsoncomposite = $ detail ;
509511 }
510512
511- if (array_key_exists ($ d_desc_attr ['name ' ], $ jsonelements )) {
513+ if (\ array_key_exists ($ d_desc_attr ['name ' ], $ jsonelements )) {
512514 $ jsonelements [$ d_desc_attr ['name ' ] . $ n ] = $ jsoncomposite ;
513515 } else {
514516 $ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
@@ -535,9 +537,11 @@ private function processSegment(&$segment, &$xmlMap, $segmentIdx, &$errors = nul
535537 *
536538 * @return array
537539 */
538- private function processService (&$ segments ): array
540+ private function processService (array &$ segments ): array
539541 {
542+ // init
540543 $ processed = [];
544+
541545 foreach ($ segments as &$ seg ) {
542546 $ jsonsegment = $ this ->processSegment ($ seg , $ this ->xmlSvc , null );
543547 $ processed [$ jsonsegment ['key ' ]] = $ jsonsegment ['value ' ];
@@ -553,7 +557,7 @@ private function processService(&$segments): array
553557 *
554558 * @return false|string
555559 */
556- public function getJson ($ pretty = false )
560+ public function getJson (bool $ pretty = false )
557561 {
558562 if ($ pretty ) {
559563 return \json_encode ($ this ->ediGroups , JSON_PRETTY_PRINT );
@@ -593,7 +597,7 @@ public function getServiceSegments()
593597 *
594598 * @return false|string
595599 */
596- public function getJsonServiceSegments ($ pretty = false )
600+ public function getJsonServiceSegments (bool $ pretty = false )
597601 {
598602 if ($ pretty ) {
599603 return \json_encode ($ this ->serviceSeg , JSON_PRETTY_PRINT );
0 commit comments