@@ -24,19 +24,19 @@ class Analyser
24
24
* @var array<mixed>
25
25
*/
26
26
private $ jsonedi ;
27
+
27
28
/**
28
29
* @var array
29
30
*/
30
31
private $ codes ;
31
32
32
- public function setXml ($ segments , $ codes ) {
33
+ public function setXml ($ segments , $ codes )
34
+ {
33
35
$ this ->segments = $ segments ;
34
36
$ this ->codes = $ codes ;
35
37
}
36
38
37
39
/**
38
- * @param string $message_xml_file
39
- *
40
40
* @return array|false
41
41
*/
42
42
public function loadMessageXml (string $ message_xml_file )
@@ -57,7 +57,6 @@ public function loadMessageXml(string $message_xml_file)
57
57
/**
58
58
* get all data element codes
59
59
*
60
- * @param string $codesXml
61
60
*
62
61
* @return array|false
63
62
*/
@@ -99,8 +98,6 @@ public function loadCodesXml(string $codesXml)
99
98
* composite_data_element same as in XML
100
99
* For single message, it's vailable also in (new EDI\Mapping\MappingProvider($version))->loadSegmentsXml()
101
100
*
102
- * @param string $segmentXmlFile
103
- * @param bool $discardOldSegments
104
101
*
105
102
* @return array|false
106
103
*/
@@ -134,7 +131,7 @@ public function loadSegmentsXml(string $segmentXmlFile, bool $discardOldSegments
134
131
$ segment = [];
135
132
$ segment ['attributes ' ] = $ this ->readAttributesArray ($ segmentNode );
136
133
$ details = $ this ->readXmlNodes ($ segmentNode );
137
- if (!empty ($ details )) {
134
+ if (! empty ($ details )) {
138
135
$ segment ['details ' ] = $ details ;
139
136
}
140
137
$ this ->segments [$ qualifier ] = $ segment ;
@@ -147,13 +144,14 @@ public function loadSegmentsXml(string $segmentXmlFile, bool $discardOldSegments
147
144
* Load segment definitions from multiple files
148
145
*
149
146
* @see Analyser::loadSegmentsXml()
147
+ *
150
148
* @param string[] $segmentXmlFiles
151
149
* @return array|false
152
150
*/
153
151
public function loadMultiSegmentsXml (array $ segmentXmlFiles )
154
152
{
155
153
foreach ($ segmentXmlFiles as $ xmlFile ) {
156
- if (!$ result = $ this ->loadSegmentsXml ($ xmlFile , false )) {
154
+ if (! $ result = $ this ->loadSegmentsXml ($ xmlFile , false )) {
157
155
return $ result ;
158
156
}
159
157
}
@@ -166,7 +164,6 @@ public function loadMultiSegmentsXml(array $segmentXmlFiles)
166
164
*
167
165
* @param array $data by EDI\Parser:parse() created array from plain EDI message
168
166
* @param array|null $rawSegments (optional) List of raw segments from EDI\Parser::getRawSegments
169
- *
170
167
* @return string file
171
168
*/
172
169
public function process (array $ data , array $ rawSegments = null ): string
@@ -185,25 +182,27 @@ public function process(array $data, array $rawSegments = null): string
185
182
$ attributes = $ this ->segments [$ id ]['attributes ' ];
186
183
$ details_desc = $ this ->segments [$ id ]['details ' ];
187
184
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 ' ;
191
188
}
192
189
$ r [] = $ idHeader ;
193
- $ r [] = ' ( ' . \wordwrap ($ attributes ['desc ' ], 75 , \PHP_EOL . ' ' ) . ') ' ;
190
+ $ r [] = ' ( ' . \wordwrap ($ attributes ['desc ' ], 75 , \PHP_EOL . ' ' ). ') ' ;
194
191
195
- $ jsonelements = ['segmentCode ' => $ id ];
192
+ $ jsonelements = [
193
+ 'segmentCode ' => $ id ,
194
+ ];
196
195
foreach ($ segment as $ idx => $ detail ) {
197
196
$ n = $ idx - 1 ;
198
- if ($ idx == 0 || !isset ($ details_desc [$ n ])) {
197
+ if ($ idx == 0 || ! isset ($ details_desc [$ n ])) {
199
198
continue ;
200
199
}
201
200
$ 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 . ' ' );
204
203
205
204
if (\is_array ($ detail )) {
206
- $ r [] = ' [ ' . $ n . '] ' . \implode (', ' , $ detail );
205
+ $ r [] = ' [ ' . $ n . '] ' . \implode (', ' , $ detail );
207
206
$ r [] = $ l1 ;
208
207
$ r [] = $ l2 ;
209
208
@@ -214,25 +213,25 @@ public function process(array $data, array $rawSegments = null): string
214
213
foreach ($ detail as $ d_n => $ d_detail ) {
215
214
$ d_sub_desc_attr = $ sub_details_desc [$ d_n ]['attributes ' ];
216
215
$ 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 . ' ' );
220
219
}
221
220
$ r [] = $ line ;
222
221
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 ' ];
226
225
227
226
$ jsoncomposite [$ d_sub_desc_attr ['name ' ]] = $ d_detail ;
228
227
if (isset ($ d_sub_desc_attr ['maxlength ' ])) {
229
- $ r [] = ' maxlen: ' . $ d_sub_desc_attr ['maxlength ' ];
228
+ $ r [] = ' maxlen: ' . $ d_sub_desc_attr ['maxlength ' ];
230
229
}
231
230
if (isset ($ d_sub_desc_attr ['required ' ])) {
232
- $ r [] = ' required: ' . $ d_sub_desc_attr ['required ' ];
231
+ $ r [] = ' required: ' . $ d_sub_desc_attr ['required ' ];
233
232
}
234
233
if (isset ($ d_sub_desc_attr ['length ' ])) {
235
- $ r [] = ' length: ' . $ d_sub_desc_attr ['length ' ];
234
+ $ r [] = ' length: ' . $ d_sub_desc_attr ['length ' ];
236
235
}
237
236
238
237
// check for skipped data
@@ -256,16 +255,16 @@ public function process(array $data, array $rawSegments = null): string
256
255
$ jsonelements [$ d_desc_attr ['name ' ]] = $ jsoncomposite ;
257
256
} else {
258
257
$ 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 ' ];
269
268
}
270
269
$ r [] = $ line ;
271
270
$ r [] = $ l1 ;
@@ -296,17 +295,13 @@ public function getJson()
296
295
297
296
/**
298
297
* read default values in given message xml
299
- *
300
- * @param \SimpleXMLElement $message
301
- *
302
- * @return array
303
298
*/
304
299
protected function readMessageDefaults (\SimpleXMLElement $ message ): array
305
300
{
306
301
// init
307
302
$ defaults = [];
308
303
309
- /* @var \SimpleXMLElement $defaultValueNode */
304
+ /** @var \SimpleXMLElement $defaultValueNode */
310
305
foreach ($ message ->defaults [0 ] ?? [] as $ defaultValueNode ) {
311
306
$ attributes = $ defaultValueNode ->attributes ();
312
307
$ id = (string ) $ attributes ->id ;
@@ -318,10 +313,6 @@ protected function readMessageDefaults(\SimpleXMLElement $message): array
318
313
319
314
/**
320
315
* read message segments and groups
321
- *
322
- * @param \SimpleXMLElement $element
323
- *
324
- * @return array
325
316
*/
326
317
protected function readXmlNodes (\SimpleXMLElement $ element ): array
327
318
{
@@ -334,7 +325,7 @@ protected function readXmlNodes(\SimpleXMLElement $element): array
334
325
$ arrayElement ['type ' ] = $ name ;
335
326
$ arrayElement ['attributes ' ] = $ this ->readAttributesArray ($ node );
336
327
$ details = $ this ->readXmlNodes ($ node );
337
- if (!empty ($ details )) {
328
+ if (! empty ($ details )) {
338
329
$ arrayElement ['details ' ] = $ details ;
339
330
}
340
331
$ arrayElements [] = $ arrayElement ;
@@ -345,10 +336,6 @@ protected function readXmlNodes(\SimpleXMLElement $element): array
345
336
346
337
/**
347
338
* return an xml elements attributes in as array
348
- *
349
- * @param \SimpleXMLElement $element
350
- *
351
- * @return array
352
339
*/
353
340
protected function readAttributesArray (\SimpleXMLElement $ element ): array
354
341
{
0 commit comments