Passed
Pull Request — master (#74)
by Mauro
08:58
created
src/XliffParser/XliffParserV2.php 1 patch
Spacing   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -16,30 +16,30 @@  discard block
 block discarded – undo
16 16
      * @inheritDoc
17 17
      * @throws \Exception
18 18
      */
19
-    public function parse( DOMDocument $dom, $output = [] ) {
19
+    public function parse(DOMDocument $dom, $output = []) {
20 20
         $i = 1;
21 21
         /** @var DOMElement $file */
22
-        foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
22
+        foreach ($dom->getElementsByTagName('file') as $file) {
23 23
 
24 24
             // metadata
25
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $dom );
25
+            $output['files'][$i]['attr'] = $this->extractMetadata($dom);
26 26
 
27 27
             // notes
28
-            $output[ 'files' ][ $i ][ 'notes' ] = $this->extractNotes( $file );
28
+            $output['files'][$i]['notes'] = $this->extractNotes($file);
29 29
 
30 30
             // trans-units
31 31
             $transUnitIdArrayForUniquenessCheck = [];
32 32
             $j                                  = 1;
33 33
             /** @var DOMElement $transUnit */
34
-            foreach ( $file->childNodes as $childNode ) {
35
-                $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j );
34
+            foreach ($file->childNodes as $childNode) {
35
+                $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j);
36 36
             }
37 37
 
38 38
             // trans-unit re-count check
39
-            $totalTransUnitsId  = count( $transUnitIdArrayForUniquenessCheck );
40
-            $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) );
41
-            if ( $totalTransUnitsId != $transUnitsUniqueId ) {
42
-                throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 );
39
+            $totalTransUnitsId  = count($transUnitIdArrayForUniquenessCheck);
40
+            $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck));
41
+            if ($totalTransUnitsId != $transUnitsUniqueId) {
42
+                throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400);
43 43
             }
44 44
 
45 45
             $i++;
@@ -53,23 +53,23 @@  discard block
 block discarded – undo
53 53
      *
54 54
      * @return array
55 55
      */
56
-    private function extractMetadata( DOMDocument $dom ) {
56
+    private function extractMetadata(DOMDocument $dom) {
57 57
         $metadata = [];
58 58
 
59
-        $xliffNode = $dom->getElementsByTagName( 'xliff' )->item( 0 );
60
-        $fileNode  = $dom->getElementsByTagName( 'file' )->item( 0 );
59
+        $xliffNode = $dom->getElementsByTagName('xliff')->item(0);
60
+        $fileNode  = $dom->getElementsByTagName('file')->item(0);
61 61
 
62 62
         // original
63
-        $metadata[ 'original' ] = ( null !== $fileNode->attributes->getNamedItem( 'original' ) ) ? $fileNode->attributes->getNamedItem( 'original' )->nodeValue : 'no-name';
63
+        $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name';
64 64
 
65 65
         // source-language
66
-        $metadata[ 'source-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'srcLang' ) ) ? $xliffNode->attributes->getNamedItem( 'srcLang' )->nodeValue : 'en-US';
66
+        $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US';
67 67
 
68 68
         // datatype
69 69
         // @TODO to be implemented
70 70
 
71 71
         // target-language
72
-        $metadata[ 'target-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'trgLang' ) ) ? $xliffNode->attributes->getNamedItem( 'trgLang' )->nodeValue : 'en-US';
72
+        $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US';
73 73
 
74 74
         // custom MateCat x-attribute
75 75
         // @TODO to be implemented
@@ -83,16 +83,16 @@  discard block
 block discarded – undo
83 83
      * @return array
84 84
      * @throws \Exception
85 85
      */
86
-    private function extractNotes( DOMElement $file ) {
86
+    private function extractNotes(DOMElement $file) {
87 87
         $notes = [];
88 88
 
89 89
         // loop <notes> to get nested <note> tag
90
-        foreach ( $file->childNodes as $childNode ) {
91
-            if ( $childNode->nodeName === 'notes' ) {
92
-                foreach ( $childNode->childNodes as $note ) {
93
-                    $noteValue = trim( $note->nodeValue );
94
-                    if ( '' !== $noteValue ) {
95
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
90
+        foreach ($file->childNodes as $childNode) {
91
+            if ($childNode->nodeName === 'notes') {
92
+                foreach ($childNode->childNodes as $note) {
93
+                    $noteValue = trim($note->nodeValue);
94
+                    if ('' !== $noteValue) {
95
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
96 96
                     }
97 97
                 }
98 98
             }
@@ -113,34 +113,34 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @throws \Exception
115 115
      */
116
-    protected function extractTransUnit( $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j ) {
116
+    protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j) {
117 117
         // metadata
118
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck );
118
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
119 119
 
120 120
         // notes
121 121
         // merge <notes> with key and key-note contained in metadata <mda:metaGroup>
122
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $transUnit );
122
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit);
123 123
 
124 124
         // uuid
125
-        foreach ( $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note ) {
126
-            if ( isset( $note[ 'raw-content' ] ) && Strings::isAValidUuid( $note[ 'raw-content' ] ) ) {
127
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ][ 'uuid' ] = $note[ 'raw-content' ];
125
+        foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) {
126
+            if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) {
127
+                $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content'];
128 128
             }
129 129
         }
130 130
 
131 131
         // original-data (exclusive for V2)
132 132
         // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata
133
-        $originalData = $this->extractTransUnitOriginalData( $transUnit );
133
+        $originalData = $this->extractTransUnitOriginalData($transUnit);
134 134
         $dataRefMap   = null;
135
-        if ( !empty( $originalData ) ) {
136
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData;
137
-            $dataRefMap                                                        = $this->getDataRefMap( $originalData );
135
+        if (!empty($originalData)) {
136
+            $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData;
137
+            $dataRefMap                                                        = $this->getDataRefMap($originalData);
138 138
         }
139 139
 
140 140
         // additionalTagData (exclusive for V2)
141
-        $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit );
142
-        if ( !empty( $additionalTagData ) ) {
143
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData;
141
+        $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit);
142
+        if (!empty($additionalTagData)) {
143
+            $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData;
144 144
         }
145 145
 
146 146
         // content
@@ -160,64 +160,64 @@  discard block
 block discarded – undo
160 160
 
161 161
         /** @var DOMElement $segment */
162 162
         $c = 0;
163
-        foreach ( $transUnit->childNodes as $segment ) {
164
-            if ( $segment->nodeName === 'segment' ) {
163
+        foreach ($transUnit->childNodes as $segment) {
164
+            if ($segment->nodeName === 'segment') {
165 165
 
166 166
                 // check segment id consistency
167
-                $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ];
168
-                $this->checkSegmentIdConsistency( $segment, $attr );
167
+                $attr = $output['files'][$i]['trans-units'][$j]['attr'];
168
+                $this->checkSegmentIdConsistency($segment, $attr);
169 169
 
170 170
                 // loop <segment> to get nested <source> and <target> tag
171
-                foreach ( $segment->childNodes as $childNode ) {
172
-                    if ( $childNode->nodeName === 'source' ) {
173
-                        $extractedSource               = $this->extractContent( $dom, $childNode );
174
-                        $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ];
171
+                foreach ($segment->childNodes as $childNode) {
172
+                    if ($childNode->nodeName === 'source') {
173
+                        $extractedSource               = $this->extractContent($dom, $childNode);
174
+                        $source['raw-content'][$c] = $extractedSource['raw-content'];
175 175
 
176
-                        if ( !empty( $originalData ) ) {
177
-                            $source[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $source[ 'raw-content' ][ $c ] );
176
+                        if (!empty($originalData)) {
177
+                            $source['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($source['raw-content'][$c]);
178 178
                         }
179 179
 
180
-                        if ( !empty( $extractedSource[ 'attr' ] ) ) {
181
-                            $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ];
180
+                        if (!empty($extractedSource['attr'])) {
181
+                            $source['attr'][$c] = $extractedSource['attr'];
182 182
                         }
183 183
 
184 184
                         // append value to 'seg-source'
185
-                        if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) {
186
-                            $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedSource[ 'raw-content' ], $originalData );
185
+                        if ($this->stringContainsMarks($extractedSource['raw-content'])) {
186
+                            $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedSource['raw-content'], $originalData);
187 187
                         } else {
188 188
                             $segSource[] = [
189
-                                    'attr'             => $this->extractTagAttributes( $segment),
190
-                                    'mid'              => count( $segSource ) > 0 ? count( $segSource ) : 0,
189
+                                    'attr'             => $this->extractTagAttributes($segment),
190
+                                    'mid'              => count($segSource) > 0 ? count($segSource) : 0,
191 191
                                     'ext-prec-tags'    => '',
192
-                                    'raw-content'      => $extractedSource[ 'raw-content' ],
193
-                                    'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedSource[ 'raw-content' ] ) : null,
192
+                                    'raw-content'      => $extractedSource['raw-content'],
193
+                                    'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedSource['raw-content']) : null,
194 194
                                     'ext-succ-tags'    => '',
195 195
                             ];
196 196
                         }
197 197
                     }
198 198
 
199
-                    if ( $childNode->nodeName === 'target' ) {
200
-                        $extractedTarget               = $this->extractContent( $dom, $childNode );
201
-                        $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ];
199
+                    if ($childNode->nodeName === 'target') {
200
+                        $extractedTarget               = $this->extractContent($dom, $childNode);
201
+                        $target['raw-content'][$c] = $extractedTarget['raw-content'];
202 202
 
203
-                        if ( !empty( $originalData ) ) {
204
-                            $target[ 'replaced-content' ][ $c ] = ( new DataRefReplacer( $dataRefMap ) )->replace( $target[ 'raw-content' ][ $c ] );
203
+                        if (!empty($originalData)) {
204
+                            $target['replaced-content'][$c] = (new DataRefReplacer($dataRefMap))->replace($target['raw-content'][$c]);
205 205
                         }
206 206
 
207
-                        if ( !empty( $extractedTarget[ 'attr' ] ) ) {
208
-                            $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ];
207
+                        if (!empty($extractedTarget['attr'])) {
208
+                            $target['attr'][$c] = $extractedTarget['attr'];
209 209
                         }
210 210
 
211 211
                         // append value to 'seg-target'
212
-                        if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) {
213
-                            $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $extractedTarget[ 'raw-content' ], $originalData );
212
+                        if ($this->stringContainsMarks($extractedTarget['raw-content'])) {
213
+                            $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode, $extractedTarget['raw-content'], $originalData);
214 214
                         } else {
215 215
                             $segTarget[] = [
216
-                                    'attr'             => $this->extractTagAttributes( $segment),
217
-                                    'mid'              => count( $segTarget ) > 0 ? count( $segTarget ) : 0,
216
+                                    'attr'             => $this->extractTagAttributes($segment),
217
+                                    'mid'              => count($segTarget) > 0 ? count($segTarget) : 0,
218 218
                                     'ext-prec-tags'    => '',
219
-                                    'raw-content'      => $extractedTarget[ 'raw-content' ],
220
-                                    'replaced-content' => ( !empty( $originalData ) ) ? ( new DataRefReplacer( $dataRefMap ) )->replace( $extractedTarget[ 'raw-content' ] ) : null,
219
+                                    'raw-content'      => $extractedTarget['raw-content'],
220
+                                    'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedTarget['raw-content']) : null,
221 221
                                     'ext-succ-tags'    => '',
222 222
                             ];
223 223
                         }
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
             }
229 229
         }
230 230
 
231
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ]     = $source;
232
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ]     = $target;
233
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource;
234
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget;
231
+        $output['files'][$i]['trans-units'][$j]['source']     = $source;
232
+        $output['files'][$i]['trans-units'][$j]['target']     = $target;
233
+        $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource;
234
+        $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget;
235 235
 
236 236
         $j++;
237 237
     }
@@ -242,41 +242,41 @@  discard block
 block discarded – undo
242 242
      *
243 243
      * @return array
244 244
      */
245
-    private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck ) {
245
+    private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck) {
246 246
         $metadata = [];
247 247
 
248 248
         // id
249
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
250
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
249
+        if (null === $transUnit->attributes->getNamedItem('id')) {
250
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
251 251
         }
252 252
 
253
-        $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue;
253
+        $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
254 254
 
255
-        if ( strlen( $id ) > 100 ) {
256
-            throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
255
+        if (strlen($id) > 100) {
256
+            throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
257 257
         }
258 258
 
259 259
         $transUnitIdArrayForUniquenessCheck[] = $id;
260
-        $metadata[ 'id' ]                     = $id;
260
+        $metadata['id']                     = $id;
261 261
 
262 262
         // translate
263
-        if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) {
264
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue;
263
+        if (null !== $transUnit->attributes->getNamedItem('translate')) {
264
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
265 265
         }
266 266
 
267 267
         // tGroupBegin
268
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) {
269
-            $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue;
268
+        if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) {
269
+            $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
270 270
         }
271 271
 
272 272
         // tGroupEnd
273
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) {
274
-            $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue;
273
+        if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) {
274
+            $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
275 275
         }
276 276
 
277 277
         // sizeRestriction
278
-        if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) {
279
-            $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue;
278
+        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) {
279
+            $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
280 280
         }
281 281
 
282 282
         return $metadata;
@@ -288,31 +288,31 @@  discard block
 block discarded – undo
288 288
      * @return array
289 289
      * @throws \Exception
290 290
      */
291
-    private function extractTransUnitOriginalData( DOMElement $transUnit ) {
291
+    private function extractTransUnitOriginalData(DOMElement $transUnit) {
292 292
         $originalData = [];
293 293
 
294 294
         // loop <originalData> to get nested content
295
-        foreach ( $transUnit->childNodes as $childNode ) {
296
-            if ( $childNode->nodeName === 'originalData' ) {
297
-                foreach ( $childNode->childNodes as $data ) {
298
-                    if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
299
-                        $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue;
295
+        foreach ($transUnit->childNodes as $childNode) {
296
+            if ($childNode->nodeName === 'originalData') {
297
+                foreach ($childNode->childNodes as $data) {
298
+                    if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
299
+                        $dataId = $data->attributes->getNamedItem('id')->nodeValue;
300 300
 
301
-                        $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue );
302
-                        $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue );
303
-                        $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue );
301
+                        $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue);
302
+                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue);
303
+                        $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue);
304 304
 
305
-                        if ( '' !== $dataValue ) {
305
+                        if ('' !== $dataValue) {
306 306
 
307
-                            $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false );
307
+                            $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false);
308 308
 
309 309
                             // restore xliff tags
310
-                            if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) {
311
-                                $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'json' ] );
310
+                            if (isset($jsonOrRawContentArray['json'])) {
311
+                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['json']);
312 312
                             }
313 313
 
314
-                            if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) {
315
-                                $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'raw-content' ] );
314
+                            if (isset($jsonOrRawContentArray['raw-content'])) {
315
+                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['raw-content']);
316 316
                             }
317 317
 
318 318
                             $originalData[] = array_merge(
@@ -337,41 +337,41 @@  discard block
 block discarded – undo
337 337
      *
338 338
      * @return array
339 339
      */
340
-    private function extractTransUnitAdditionalTagData( DOMElement $transUnit ) {
340
+    private function extractTransUnitAdditionalTagData(DOMElement $transUnit) {
341 341
         $additionalTagData = [];
342 342
 
343 343
         // loop <originalData> to get nested content
344
-        foreach ( $transUnit->childNodes as $childNode ) {
345
-            if ( $childNode->nodeName === 'memsource:additionalTagData' ) {
346
-                foreach ( $childNode->childNodes as $data ) {
344
+        foreach ($transUnit->childNodes as $childNode) {
345
+            if ($childNode->nodeName === 'memsource:additionalTagData') {
346
+                foreach ($childNode->childNodes as $data) {
347 347
                     $dataArray = [];
348 348
 
349 349
                     // id
350
-                    if ( $data->nodeName === 'memsource:tag' ) {
351
-                        if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
352
-                            $dataId                      = $data->attributes->getNamedItem( 'id' )->nodeValue;
353
-                            $dataArray[ 'attr' ][ 'id' ] = $dataId;
350
+                    if ($data->nodeName === 'memsource:tag') {
351
+                        if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
352
+                            $dataId                      = $data->attributes->getNamedItem('id')->nodeValue;
353
+                            $dataArray['attr']['id'] = $dataId;
354 354
                         }
355 355
                     }
356 356
 
357 357
                     // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0
358 358
                     // PHP 5.6 check: in php 5.6 $data->childNodes can be null
359
-                    if ( $data->childNodes != null ) {
359
+                    if ($data->childNodes != null) {
360 360
 
361 361
                         // content
362
-                        foreach ( $data->childNodes as $datum ) {
363
-                            if ( $datum->nodeName === 'memsource:tagId' ) {
364
-                                $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue;
362
+                        foreach ($data->childNodes as $datum) {
363
+                            if ($datum->nodeName === 'memsource:tagId') {
364
+                                $dataArray['raw-content']['tagId'] = $datum->nodeValue;
365 365
                             }
366 366
 
367
-                            if ( $datum->nodeName === 'memsource:type' ) {
368
-                                $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue;
367
+                            if ($datum->nodeName === 'memsource:type') {
368
+                                $dataArray['raw-content']['type'] = $datum->nodeValue;
369 369
                             }
370 370
                         }
371 371
 
372 372
                     }
373 373
 
374
-                    if ( !empty( $dataArray ) ) {
374
+                    if (!empty($dataArray)) {
375 375
                         $additionalTagData[] = $dataArray;
376 376
                     }
377 377
                 }
@@ -387,15 +387,15 @@  discard block
 block discarded – undo
387 387
      * @param DOMElement $segment
388 388
      * @param array      $attr
389 389
      */
390
-    private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) {
391
-        if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) {
392
-            $id  = $segment->attributes->getNamedItem( 'id' )->nodeValue;
393
-            $min = (int)$attr[ 'tGroupBegin' ];
394
-            $max = (int)$attr[ 'tGroupEnd' ];
395
-
396
-            if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) {
397
-                if ( $this->logger ) {
398
-                    $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' );
390
+    private function checkSegmentIdConsistency(DOMElement $segment, array $attr) {
391
+        if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) {
392
+            $id  = $segment->attributes->getNamedItem('id')->nodeValue;
393
+            $min = (int)$attr['tGroupBegin'];
394
+            $max = (int)$attr['tGroupEnd'];
395
+
396
+            if (false === (($min <= $id) && ($id <= $max))) {
397
+                if ($this->logger) {
398
+                    $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd');
399 399
                 }
400 400
             }
401 401
         }
@@ -407,31 +407,31 @@  discard block
 block discarded – undo
407 407
      * @return array
408 408
      * @throws \Exception
409 409
      */
410
-    private function extractTransUnitNotes( DOMElement $transUnit ) {
410
+    private function extractTransUnitNotes(DOMElement $transUnit) {
411 411
         $notes = [];
412 412
 
413 413
         // loop <notes> to get nested <note> tag
414
-        foreach ( $transUnit->childNodes as $childNode ) {
415
-            if ( $childNode->nodeName == 'notes' ) {
416
-                foreach ( $childNode->childNodes as $note ) {
417
-                    $noteValue = trim( $note->nodeValue );
418
-                    if ( '' !== $noteValue ) {
419
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
414
+        foreach ($transUnit->childNodes as $childNode) {
415
+            if ($childNode->nodeName == 'notes') {
416
+                foreach ($childNode->childNodes as $note) {
417
+                    $noteValue = trim($note->nodeValue);
418
+                    if ('' !== $noteValue) {
419
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
420 420
                     }
421 421
                 }
422 422
             }
423 423
 
424
-            if ( $childNode->nodeName === 'mda:metadata' ) {
425
-                foreach ( $childNode->childNodes as $metadata ) {
426
-                    if ( $metadata->nodeName === 'mda:metaGroup' ) {
427
-                        foreach ( $metadata->childNodes as $meta ) {
428
-                            if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) {
429
-                                $type      = $meta->attributes->getNamedItem( 'type' )->nodeValue;
430
-                                $metaValue = trim( $meta->nodeValue );
424
+            if ($childNode->nodeName === 'mda:metadata') {
425
+                foreach ($childNode->childNodes as $metadata) {
426
+                    if ($metadata->nodeName === 'mda:metaGroup') {
427
+                        foreach ($metadata->childNodes as $meta) {
428
+                            if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
429
+                                $type      = $meta->attributes->getNamedItem('type')->nodeValue;
430
+                                $metaValue = trim($meta->nodeValue);
431 431
 
432
-                                if ( '' !== $metaValue ) {
432
+                                if ('' !== $metaValue) {
433 433
                                     $notes[] = array_merge(
434
-                                            $this->JSONOrRawContentArray( $metaValue ),
434
+                                            $this->JSONOrRawContentArray($metaValue),
435 435
                                             [
436 436
                                                     'attr' => [
437 437
                                                             'type' => $type
Please login to merge, or discard this patch.