@@ -24,19 +24,19 @@ class Analyser
2424 * @var array<mixed>
2525 */
2626 private $ jsonedi ;
27+
2728 /**
2829 * @var array
2930 */
3031 private $ codes ;
3132
32- public function setXml ($ segments , $ codes ) {
33+ public function setXml ($ segments , $ codes )
34+ {
3335 $ this ->segments = $ segments ;
3436 $ this ->codes = $ codes ;
3537 }
3638
3739 /**
38- * @param string $message_xml_file
39- *
4040 * @return array|false
4141 */
4242 public function loadMessageXml (string $ message_xml_file )
@@ -57,7 +57,6 @@ public function loadMessageXml(string $message_xml_file)
5757 /**
5858 * get all data element codes
5959 *
60- * @param string $codesXml
6160 *
6261 * @return array|false
6362 */
@@ -99,8 +98,6 @@ public function loadCodesXml(string $codesXml)
9998 * composite_data_element same as in XML
10099 * For single message, it's vailable also in (new EDI\Mapping\MappingProvider($version))->loadSegmentsXml()
101100 *
102- * @param string $segmentXmlFile
103- * @param bool $discardOldSegments
104101 *
105102 * @return array|false
106103 */
@@ -134,7 +131,7 @@ public function loadSegmentsXml(string $segmentXmlFile, bool $discardOldSegments
134131 $ segment = [];
135132 $ segment ['attributes ' ] = $ this ->readAttributesArray ($ segmentNode );
136133 $ details = $ this ->readXmlNodes ($ segmentNode );
137- if (!empty ($ details )) {
134+ if (! empty ($ details )) {
138135 $ segment ['details ' ] = $ details ;
139136 }
140137 $ this ->segments [$ qualifier ] = $ segment ;
@@ -147,13 +144,14 @@ public function loadSegmentsXml(string $segmentXmlFile, bool $discardOldSegments
147144 * Load segment definitions from multiple files
148145 *
149146 * @see Analyser::loadSegmentsXml()
147+ *
150148 * @param string[] $segmentXmlFiles
151149 * @return array|false
152150 */
153151 public function loadMultiSegmentsXml (array $ segmentXmlFiles )
154152 {
155153 foreach ($ segmentXmlFiles as $ xmlFile ) {
156- if (!$ result = $ this ->loadSegmentsXml ($ xmlFile , false )) {
154+ if (! $ result = $ this ->loadSegmentsXml ($ xmlFile , false )) {
157155 return $ result ;
158156 }
159157 }
@@ -166,7 +164,6 @@ public function loadMultiSegmentsXml(array $segmentXmlFiles)
166164 *
167165 * @param array $data by EDI\Parser:parse() created array from plain EDI message
168166 * @param array|null $rawSegments (optional) List of raw segments from EDI\Parser::getRawSegments
169- *
170167 * @return string file
171168 */
172169 public function process (array $ data , array $ rawSegments = null ): string
@@ -185,25 +182,27 @@ public function process(array $data, array $rawSegments = null): string
185182 $ attributes = $ this ->segments [$ id ]['attributes ' ];
186183 $ details_desc = $ this ->segments [$ id ]['details ' ];
187184
188- $ idHeader = $ id . ' - ' . $ attributes ['name ' ];
189- if ($ this ->directory && $ id !== 'UNB ' ) {
190- $ idHeader .= ' https://service.unece.org/trade/untdid/ ' . strtolower ($ this ->directory ) . '/trsd/trsd ' . strtolower ($ id ) . '.htm ' ;
185+ $ idHeader = $ id. ' - ' . $ attributes ['name ' ];
186+ if ($ this ->directory && $ id !== 'UNB ' ) {
187+ $ idHeader .= ' https://service.unece.org/trade/untdid/ ' . strtolower ($ this ->directory ). '/trsd/trsd ' . strtolower ($ id ). '.htm ' ;
191188 }
192189 $ r [] = $ idHeader ;
193- $ r [] = ' ( ' . \wordwrap ($ attributes ['desc ' ], 75 , \PHP_EOL . ' ' ) . ') ' ;
190+ $ r [] = ' ( ' . \wordwrap ($ attributes ['desc ' ], 75 , \PHP_EOL . ' ' ). ') ' ;
194191
195- $ jsonelements = ['segmentCode ' => $ id ];
192+ $ jsonelements = [
193+ 'segmentCode ' => $ id ,
194+ ];
196195 foreach ($ segment as $ idx => $ detail ) {
197196 $ n = $ idx - 1 ;
198- if ($ idx == 0 || !isset ($ details_desc [$ n ])) {
197+ if ($ idx == 0 || ! isset ($ details_desc [$ n ])) {
199198 continue ;
200199 }
201200 $ d_desc_attr = $ details_desc [$ n ]['attributes ' ];
202- $ l1 = ' ' . $ d_desc_attr ['id ' ] . ' - ' . $ d_desc_attr ['name ' ];
203- $ l2 = ' ' . \wordwrap ($ d_desc_attr ['desc ' ], 71 , \PHP_EOL . ' ' );
201+ $ l1 = ' ' . $ d_desc_attr ['id ' ]. ' - ' . $ d_desc_attr ['name ' ];
202+ $ l2 = ' ' . \wordwrap ($ d_desc_attr ['desc ' ], 71 , \PHP_EOL . ' ' );
204203
205204 if (\is_array ($ detail )) {
206- $ r [] = ' [ ' . $ n . '] ' . \implode (', ' , $ detail );
205+ $ r [] = ' [ ' . $ n . '] ' . \implode (', ' , $ detail );
207206 $ r [] = $ l1 ;
208207 $ r [] = $ l2 ;
209208
@@ -214,25 +213,25 @@ public function process(array $data, array $rawSegments = null): string
214213 foreach ($ detail as $ d_n => $ d_detail ) {
215214 $ d_sub_desc_attr = $ sub_details_desc [$ d_n ]['attributes ' ];
216215 $ codeElementId = $ d_sub_desc_attr ['id ' ];
217- $ line = ' [ ' . $ d_n . '] ' . $ d_detail ;
218- if (isset ($ this ->codes [(int )$ codeElementId ][$ d_detail ])){
219- $ line .= ' - ' . \wordwrap ($ this ->codes [$ codeElementId ][$ d_detail ], 69 , \PHP_EOL . ' ' );
216+ $ line = ' [ ' . $ d_n. '] ' . $ d_detail ;
217+ if (isset ($ this ->codes [(int ) $ codeElementId ][$ d_detail ])) {
218+ $ line .= ' - ' . \wordwrap ($ this ->codes [$ codeElementId ][$ d_detail ], 69 , \PHP_EOL . ' ' );
220219 }
221220 $ r [] = $ line ;
222221
223- $ r [] = ' id: ' . $ codeElementId . ' - ' . $ d_sub_desc_attr ['name ' ];
224- $ r [] = ' ' . \wordwrap ($ d_sub_desc_attr ['desc ' ], 69 , \PHP_EOL . ' ' );
225- $ r [] = ' type: ' . $ d_sub_desc_attr ['type ' ];
222+ $ r [] = ' id: ' . $ codeElementId. ' - ' . $ d_sub_desc_attr ['name ' ];
223+ $ r [] = ' ' . \wordwrap ($ d_sub_desc_attr ['desc ' ], 69 , \PHP_EOL . ' ' );
224+ $ r [] = ' type: ' . $ d_sub_desc_attr ['type ' ];
226225
227226 $ jsoncomposite [$ d_sub_desc_attr ['name ' ]] = $ d_detail ;
228227 if (isset ($ d_sub_desc_attr ['maxlength ' ])) {
229- $ r [] = ' maxlen: ' . $ d_sub_desc_attr ['maxlength ' ];
228+ $ r [] = ' maxlen: ' . $ d_sub_desc_attr ['maxlength ' ];
230229 }
231230 if (isset ($ d_sub_desc_attr ['required ' ])) {
232- $ r [] = ' required: ' . $ d_sub_desc_attr ['required ' ];
231+ $ r [] = ' required: ' . $ d_sub_desc_attr ['required ' ];
233232 }
234233 if (isset ($ d_sub_desc_attr ['length ' ])) {
235- $ r [] = ' length: ' . $ d_sub_desc_attr ['length ' ];
234+ $ r [] = ' length: ' . $ d_sub_desc_attr ['length ' ];
236235 }
237236
238237 // check for skipped data
@@ -256,16 +255,16 @@ public function process(array $data, array $rawSegments = null): string
256255 $ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
257256 } else {
258257 $ codeElementId = $ d_desc_attr ['id ' ];
259- $ line = ' [ ' . $ n . '] ' . $ detail ;
260- if (isset ($ this ->codes [(int )$ codeElementId ][$ detail ])){
261- /*
262- * for retrieving code element description when first element of the segment
263- * is a data element and not a composite one. Ex: NAD segment.
264- * We rewrite also l1 line for adding 'id:' prefix before data element id.
265- * It's just a cosmetic fix
266- */
267- $ line .= ' - ' . \wordwrap ($ this ->codes [$ codeElementId ][$ detail ], 71 , \PHP_EOL . ' ' );
268- $ l1 = ' id: ' . $ d_desc_attr ['id ' ] . ' - ' . $ d_desc_attr ['name ' ];
258+ $ line = ' [ ' . $ n . '] ' . $ detail ;
259+ if (isset ($ this ->codes [(int ) $ codeElementId ][$ detail ])) {
260+ /*
261+ * for retrieving code element description when first element of the segment
262+ * is a data element and not a composite one. Ex: NAD segment.
263+ * We rewrite also l1 line for adding 'id:' prefix before data element id.
264+ * It's just a cosmetic fix
265+ */
266+ $ line .= ' - ' . \wordwrap ($ this ->codes [$ codeElementId ][$ detail ], 71 , \PHP_EOL . ' ' );
267+ $ l1 = ' id: ' . $ d_desc_attr ['id ' ]. ' - ' . $ d_desc_attr ['name ' ];
269268 }
270269 $ r [] = $ line ;
271270 $ r [] = $ l1 ;
@@ -296,17 +295,13 @@ public function getJson()
296295
297296 /**
298297 * read default values in given message xml
299- *
300- * @param \SimpleXMLElement $message
301- *
302- * @return array
303298 */
304299 protected function readMessageDefaults (\SimpleXMLElement $ message ): array
305300 {
306301 // init
307302 $ defaults = [];
308303
309- /* @var \SimpleXMLElement $defaultValueNode */
304+ /** @var \SimpleXMLElement $defaultValueNode */
310305 foreach ($ message ->defaults [0 ] ?? [] as $ defaultValueNode ) {
311306 $ attributes = $ defaultValueNode ->attributes ();
312307 $ id = (string ) $ attributes ->id ;
@@ -318,10 +313,6 @@ protected function readMessageDefaults(\SimpleXMLElement $message): array
318313
319314 /**
320315 * read message segments and groups
321- *
322- * @param \SimpleXMLElement $element
323- *
324- * @return array
325316 */
326317 protected function readXmlNodes (\SimpleXMLElement $ element ): array
327318 {
@@ -334,7 +325,7 @@ protected function readXmlNodes(\SimpleXMLElement $element): array
334325 $ arrayElement ['type ' ] = $ name ;
335326 $ arrayElement ['attributes ' ] = $ this ->readAttributesArray ($ node );
336327 $ details = $ this ->readXmlNodes ($ node );
337- if (!empty ($ details )) {
328+ if (! empty ($ details )) {
338329 $ arrayElement ['details ' ] = $ details ;
339330 }
340331 $ arrayElements [] = $ arrayElement ;
@@ -345,10 +336,6 @@ protected function readXmlNodes(\SimpleXMLElement $element): array
345336
346337 /**
347338 * return an xml elements attributes in as array
348- *
349- * @param \SimpleXMLElement $element
350- *
351- * @return array
352339 */
353340 protected function readAttributesArray (\SimpleXMLElement $ element ): array
354341 {
0 commit comments