Passed
Push — master ( 9cdc2c...cd421c )
by Domenico
01:27 queued 17s
created
src/XliffParser/XliffParserV2.php 1 patch
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@  discard block
 block discarded – undo
15 15
      * @inheritDoc
16 16
      * @throws \Exception
17 17
      */
18
-    public function parse( DOMDocument $dom, $output = [] ) {
18
+    public function parse(DOMDocument $dom, $output = []) {
19 19
         $i = 1;
20 20
         /** @var DOMElement $file */
21
-        foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
21
+        foreach ($dom->getElementsByTagName('file') as $file) {
22 22
 
23 23
             // metadata
24
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $dom );
24
+            $output['files'][$i]['attr'] = $this->extractMetadata($dom);
25 25
 
26 26
             // notes
27
-            $output[ 'files' ][ $i ][ 'notes' ] = $this->extractNotes( $file );
27
+            $output['files'][$i]['notes'] = $this->extractNotes($file);
28 28
 
29 29
             // trans-units
30 30
             $transUnitIdArrayForUniquenessCheck = [];
31 31
             $j                                  = 1;
32 32
             /** @var DOMElement $transUnit */
33
-            foreach ( $file->childNodes as $childNode ) {
34
-                $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j );
33
+            foreach ($file->childNodes as $childNode) {
34
+                $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j);
35 35
             }
36 36
 
37 37
             // trans-unit re-count check
38
-            $totalTransUnitsId  = count( $transUnitIdArrayForUniquenessCheck );
39
-            $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) );
40
-            if ( $totalTransUnitsId != $transUnitsUniqueId ) {
41
-                throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 );
38
+            $totalTransUnitsId  = count($transUnitIdArrayForUniquenessCheck);
39
+            $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck));
40
+            if ($totalTransUnitsId != $transUnitsUniqueId) {
41
+                throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400);
42 42
             }
43 43
 
44 44
             $i++;
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return array
54 54
      */
55
-    private function extractMetadata( DOMDocument $dom ) {
55
+    private function extractMetadata(DOMDocument $dom) {
56 56
         $metadata = [];
57 57
 
58
-        $xliffNode = $dom->getElementsByTagName( 'xliff' )->item( 0 );
59
-        $fileNode  = $dom->getElementsByTagName( 'file' )->item( 0 );
58
+        $xliffNode = $dom->getElementsByTagName('xliff')->item(0);
59
+        $fileNode  = $dom->getElementsByTagName('file')->item(0);
60 60
 
61 61
         // original
62
-        $metadata[ 'original' ] = ( null !== $fileNode->attributes->getNamedItem( 'original' ) ) ? $fileNode->attributes->getNamedItem( 'original' )->nodeValue : 'no-name';
62
+        $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name';
63 63
 
64 64
         // source-language
65
-        $metadata[ 'source-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'srcLang' ) ) ? $xliffNode->attributes->getNamedItem( 'srcLang' )->nodeValue : 'en-US';
65
+        $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US';
66 66
 
67 67
         // datatype
68 68
         // @TODO to be implemented
69 69
 
70 70
         // target-language
71
-        $metadata[ 'target-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'trgLang' ) ) ? $xliffNode->attributes->getNamedItem( 'trgLang' )->nodeValue : 'en-US';
71
+        $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US';
72 72
 
73 73
         // custom MateCat x-attribute
74 74
         // @TODO to be implemented
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
      * @return array
83 83
      * @throws \Exception
84 84
      */
85
-    private function extractNotes( DOMElement $file ) {
85
+    private function extractNotes(DOMElement $file) {
86 86
         $notes = [];
87 87
 
88 88
         // loop <notes> to get nested <note> tag
89
-        foreach ( $file->childNodes as $childNode ) {
90
-            if ( $childNode->nodeName === 'notes' ) {
91
-                foreach ( $childNode->childNodes as $note ) {
92
-                    $noteValue = trim( $note->nodeValue );
93
-                    if ( '' !== $noteValue ) {
94
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
89
+        foreach ($file->childNodes as $childNode) {
90
+            if ($childNode->nodeName === 'notes') {
91
+                foreach ($childNode->childNodes as $note) {
92
+                    $noteValue = trim($note->nodeValue);
93
+                    if ('' !== $noteValue) {
94
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
95 95
                     }
96 96
                 }
97 97
             }
@@ -113,32 +113,32 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @throws \Exception
115 115
      */
116
-    protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) {
116
+    protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []) {
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 );
134
-        if ( !empty( $originalData ) ) {
135
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData;
133
+        $originalData = $this->extractTransUnitOriginalData($transUnit);
134
+        if (!empty($originalData)) {
135
+            $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData;
136 136
         }
137 137
 
138 138
         // additionalTagData (exclusive for V2)
139
-        $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit );
140
-        if ( !empty( $additionalTagData ) ) {
141
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData;
139
+        $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit);
140
+        if (!empty($additionalTagData)) {
141
+            $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData;
142 142
         }
143 143
 
144 144
         // content
@@ -158,54 +158,54 @@  discard block
 block discarded – undo
158 158
 
159 159
         /** @var DOMElement $segment */
160 160
         $c = 0;
161
-        foreach ( $transUnit->childNodes as $segment ) {
162
-            if ( $segment->nodeName === 'segment' ) {
161
+        foreach ($transUnit->childNodes as $segment) {
162
+            if ($segment->nodeName === 'segment') {
163 163
 
164 164
                 // check segment id consistency
165
-                $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ];
166
-                $this->checkSegmentIdConsistency( $segment, $attr );
165
+                $attr = $output['files'][$i]['trans-units'][$j]['attr'];
166
+                $this->checkSegmentIdConsistency($segment, $attr);
167 167
 
168 168
                 // loop <segment> to get nested <source> and <target> tag
169
-                foreach ( $segment->childNodes as $childNode ) {
170
-                    if ( $childNode->nodeName === 'source' ) {
171
-                        $extractedSource               = $this->extractContent( $dom, $childNode );
172
-                        $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ];
169
+                foreach ($segment->childNodes as $childNode) {
170
+                    if ($childNode->nodeName === 'source') {
171
+                        $extractedSource               = $this->extractContent($dom, $childNode);
172
+                        $source['raw-content'][$c] = $extractedSource['raw-content'];
173 173
 
174
-                        if ( !empty( $extractedSource[ 'attr' ] ) ) {
175
-                            $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ];
174
+                        if (!empty($extractedSource['attr'])) {
175
+                            $source['attr'][$c] = $extractedSource['attr'];
176 176
                         }
177 177
 
178 178
                         // append value to 'seg-source'
179
-                        if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) {
180
-                            $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode );
179
+                        if ($this->stringContainsMarks($extractedSource['raw-content'])) {
180
+                            $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode);
181 181
                         } else {
182 182
                             $segSource[] = [
183
-                                    'attr'             => $this->extractTagAttributes( $segment),
184
-                                    'mid'              => count( $segSource ) > 0 ? count( $segSource ) : 0,
183
+                                    'attr'             => $this->extractTagAttributes($segment),
184
+                                    'mid'              => count($segSource) > 0 ? count($segSource) : 0,
185 185
                                     'ext-prec-tags'    => '',
186
-                                    'raw-content'      => $extractedSource[ 'raw-content' ],
186
+                                    'raw-content'      => $extractedSource['raw-content'],
187 187
                                     'ext-succ-tags'    => '',
188 188
                             ];
189 189
                         }
190 190
                     }
191 191
 
192
-                    if ( $childNode->nodeName === 'target' ) {
193
-                        $extractedTarget               = $this->extractContent( $dom, $childNode );
194
-                        $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ];
192
+                    if ($childNode->nodeName === 'target') {
193
+                        $extractedTarget               = $this->extractContent($dom, $childNode);
194
+                        $target['raw-content'][$c] = $extractedTarget['raw-content'];
195 195
 
196
-                        if ( !empty( $extractedTarget[ 'attr' ] ) ) {
197
-                            $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ];
196
+                        if (!empty($extractedTarget['attr'])) {
197
+                            $target['attr'][$c] = $extractedTarget['attr'];
198 198
                         }
199 199
 
200 200
                         // append value to 'seg-target'
201
-                        if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) {
202
-                            $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode );
201
+                        if ($this->stringContainsMarks($extractedTarget['raw-content'])) {
202
+                            $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode);
203 203
                         } else {
204 204
                             $segTarget[] = [
205
-                                    'attr'             => $this->extractTagAttributes( $segment),
206
-                                    'mid'              => count( $segTarget ) > 0 ? count( $segTarget ) : 0,
205
+                                    'attr'             => $this->extractTagAttributes($segment),
206
+                                    'mid'              => count($segTarget) > 0 ? count($segTarget) : 0,
207 207
                                     'ext-prec-tags'    => '',
208
-                                    'raw-content'      => $extractedTarget[ 'raw-content' ],
208
+                                    'raw-content'      => $extractedTarget['raw-content'],
209 209
                                     'ext-succ-tags'    => '',
210 210
                             ];
211 211
                         }
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
             }
217 217
         }
218 218
 
219
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ]     = $source;
220
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ]     = $target;
221
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource;
222
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget;
219
+        $output['files'][$i]['trans-units'][$j]['source']     = $source;
220
+        $output['files'][$i]['trans-units'][$j]['target']     = $target;
221
+        $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource;
222
+        $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget;
223 223
 
224 224
         $j++;
225 225
     }
@@ -230,41 +230,41 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return array
232 232
      */
233
-    private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck ) {
233
+    private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck) {
234 234
         $metadata = [];
235 235
 
236 236
         // id
237
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
238
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
237
+        if (null === $transUnit->attributes->getNamedItem('id')) {
238
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
239 239
         }
240 240
 
241
-        $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue;
241
+        $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
242 242
 
243
-        if ( strlen( $id ) > 100 ) {
244
-            throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
243
+        if (strlen($id) > 100) {
244
+            throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
245 245
         }
246 246
 
247 247
         $transUnitIdArrayForUniquenessCheck[] = $id;
248
-        $metadata[ 'id' ]                     = $id;
248
+        $metadata['id']                     = $id;
249 249
 
250 250
         // translate
251
-        if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) {
252
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue;
251
+        if (null !== $transUnit->attributes->getNamedItem('translate')) {
252
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
253 253
         }
254 254
 
255 255
         // tGroupBegin
256
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) {
257
-            $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue;
256
+        if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) {
257
+            $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
258 258
         }
259 259
 
260 260
         // tGroupEnd
261
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) {
262
-            $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue;
261
+        if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) {
262
+            $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
263 263
         }
264 264
 
265 265
         // sizeRestriction
266
-        if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) {
267
-            $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue;
266
+        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) {
267
+            $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
268 268
         }
269 269
 
270 270
         return $metadata;
@@ -276,31 +276,31 @@  discard block
 block discarded – undo
276 276
      * @return array
277 277
      * @throws \Exception
278 278
      */
279
-    private function extractTransUnitOriginalData( DOMElement $transUnit ) {
279
+    private function extractTransUnitOriginalData(DOMElement $transUnit) {
280 280
         $originalData = [];
281 281
 
282 282
         // loop <originalData> to get nested content
283
-        foreach ( $transUnit->childNodes as $childNode ) {
284
-            if ( $childNode->nodeName === 'originalData' ) {
285
-                foreach ( $childNode->childNodes as $data ) {
286
-                    if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
287
-                        $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue;
283
+        foreach ($transUnit->childNodes as $childNode) {
284
+            if ($childNode->nodeName === 'originalData') {
285
+                foreach ($childNode->childNodes as $data) {
286
+                    if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
287
+                        $dataId = $data->attributes->getNamedItem('id')->nodeValue;
288 288
 
289
-                        $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue );
290
-                        $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue );
291
-                        $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue );
289
+                        $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue);
290
+                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue);
291
+                        $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue);
292 292
 
293
-                        if ( '' !== $dataValue ) {
293
+                        if ('' !== $dataValue) {
294 294
 
295
-                            $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false );
295
+                            $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false);
296 296
 
297 297
                             // restore xliff tags
298
-                            if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) {
299
-                                $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'json' ] );
298
+                            if (isset($jsonOrRawContentArray['json'])) {
299
+                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['json']);
300 300
                             }
301 301
 
302
-                            if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) {
303
-                                $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'raw-content' ] );
302
+                            if (isset($jsonOrRawContentArray['raw-content'])) {
303
+                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['raw-content']);
304 304
                             }
305 305
 
306 306
                             $originalData[] = array_merge(
@@ -325,41 +325,41 @@  discard block
 block discarded – undo
325 325
      *
326 326
      * @return array
327 327
      */
328
-    private function extractTransUnitAdditionalTagData( DOMElement $transUnit ) {
328
+    private function extractTransUnitAdditionalTagData(DOMElement $transUnit) {
329 329
         $additionalTagData = [];
330 330
 
331 331
         // loop <originalData> to get nested content
332
-        foreach ( $transUnit->childNodes as $childNode ) {
333
-            if ( $childNode->nodeName === 'memsource:additionalTagData' ) {
334
-                foreach ( $childNode->childNodes as $data ) {
332
+        foreach ($transUnit->childNodes as $childNode) {
333
+            if ($childNode->nodeName === 'memsource:additionalTagData') {
334
+                foreach ($childNode->childNodes as $data) {
335 335
                     $dataArray = [];
336 336
 
337 337
                     // id
338
-                    if ( $data->nodeName === 'memsource:tag' ) {
339
-                        if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
340
-                            $dataId                      = $data->attributes->getNamedItem( 'id' )->nodeValue;
341
-                            $dataArray[ 'attr' ][ 'id' ] = $dataId;
338
+                    if ($data->nodeName === 'memsource:tag') {
339
+                        if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
340
+                            $dataId                      = $data->attributes->getNamedItem('id')->nodeValue;
341
+                            $dataArray['attr']['id'] = $dataId;
342 342
                         }
343 343
                     }
344 344
 
345 345
                     // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0
346 346
                     // PHP 5.6 check: in php 5.6 $data->childNodes can be null
347
-                    if ( $data->childNodes != null ) {
347
+                    if ($data->childNodes != null) {
348 348
 
349 349
                         // content
350
-                        foreach ( $data->childNodes as $datum ) {
351
-                            if ( $datum->nodeName === 'memsource:tagId' ) {
352
-                                $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue;
350
+                        foreach ($data->childNodes as $datum) {
351
+                            if ($datum->nodeName === 'memsource:tagId') {
352
+                                $dataArray['raw-content']['tagId'] = $datum->nodeValue;
353 353
                             }
354 354
 
355
-                            if ( $datum->nodeName === 'memsource:type' ) {
356
-                                $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue;
355
+                            if ($datum->nodeName === 'memsource:type') {
356
+                                $dataArray['raw-content']['type'] = $datum->nodeValue;
357 357
                             }
358 358
                         }
359 359
 
360 360
                     }
361 361
 
362
-                    if ( !empty( $dataArray ) ) {
362
+                    if (!empty($dataArray)) {
363 363
                         $additionalTagData[] = $dataArray;
364 364
                     }
365 365
                 }
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
      * @param DOMElement $segment
376 376
      * @param array      $attr
377 377
      */
378
-    private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) {
379
-        if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) {
380
-            $id  = $segment->attributes->getNamedItem( 'id' )->nodeValue;
381
-            $min = (int)$attr[ 'tGroupBegin' ];
382
-            $max = (int)$attr[ 'tGroupEnd' ];
383
-
384
-            if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) {
385
-                if ( $this->logger ) {
386
-                    $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' );
378
+    private function checkSegmentIdConsistency(DOMElement $segment, array $attr) {
379
+        if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) {
380
+            $id  = $segment->attributes->getNamedItem('id')->nodeValue;
381
+            $min = (int)$attr['tGroupBegin'];
382
+            $max = (int)$attr['tGroupEnd'];
383
+
384
+            if (false === (($min <= $id) && ($id <= $max))) {
385
+                if ($this->logger) {
386
+                    $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd');
387 387
                 }
388 388
             }
389 389
         }
@@ -395,31 +395,31 @@  discard block
 block discarded – undo
395 395
      * @return array
396 396
      * @throws \Exception
397 397
      */
398
-    private function extractTransUnitNotes( DOMElement $transUnit ) {
398
+    private function extractTransUnitNotes(DOMElement $transUnit) {
399 399
         $notes = [];
400 400
 
401 401
         // loop <notes> to get nested <note> tag
402
-        foreach ( $transUnit->childNodes as $childNode ) {
403
-            if ( $childNode->nodeName == 'notes' ) {
404
-                foreach ( $childNode->childNodes as $note ) {
405
-                    $noteValue = trim( $note->nodeValue );
406
-                    if ( '' !== $noteValue ) {
407
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
402
+        foreach ($transUnit->childNodes as $childNode) {
403
+            if ($childNode->nodeName == 'notes') {
404
+                foreach ($childNode->childNodes as $note) {
405
+                    $noteValue = trim($note->nodeValue);
406
+                    if ('' !== $noteValue) {
407
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
408 408
                     }
409 409
                 }
410 410
             }
411 411
 
412
-            if ( $childNode->nodeName === 'mda:metadata' ) {
413
-                foreach ( $childNode->childNodes as $metadata ) {
414
-                    if ( $metadata->nodeName === 'mda:metaGroup' ) {
415
-                        foreach ( $metadata->childNodes as $meta ) {
416
-                            if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) {
417
-                                $type      = $meta->attributes->getNamedItem( 'type' )->nodeValue;
418
-                                $metaValue = trim( $meta->nodeValue );
412
+            if ($childNode->nodeName === 'mda:metadata') {
413
+                foreach ($childNode->childNodes as $metadata) {
414
+                    if ($metadata->nodeName === 'mda:metaGroup') {
415
+                        foreach ($metadata->childNodes as $meta) {
416
+                            if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
417
+                                $type      = $meta->attributes->getNamedItem('type')->nodeValue;
418
+                                $metaValue = trim($meta->nodeValue);
419 419
 
420
-                                if ( '' !== $metaValue ) {
420
+                                if ('' !== $metaValue) {
421 421
                                     $notes[] = array_merge(
422
-                                            $this->JSONOrRawContentArray( $metaValue ),
422
+                                            $this->JSONOrRawContentArray($metaValue),
423 423
                                             [
424 424
                                                     'attr' => [
425 425
                                                             'type' => $type
Please login to merge, or discard this patch.
src/XliffParser/AbstractXliffParser.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * @param string|null          $xliffProprietary
38 38
      * @param LoggerInterface|null $logger
39 39
      */
40
-    public function __construct( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) {
40
+    public function __construct($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) {
41 41
         $this->xliffVersion     = $xliffVersion;
42 42
         $this->logger           = $logger;
43 43
         $this->xliffProprietary = $xliffProprietary;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @return string
48 48
      */
49 49
     protected function getTuTagName() {
50
-        return ( $this->xliffVersion === 1 ) ? 'trans-unit' : 'unit';
50
+        return ($this->xliffVersion === 1) ? 'trans-unit' : 'unit';
51 51
     }
52 52
 
53 53
     /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return array
57 57
      */
58
-    abstract public function parse( DOMDocument $dom, $output = [] );
58
+    abstract public function parse(DOMDocument $dom, $output = []);
59 59
 
60 60
     /**
61 61
      * Extract trans-unit content from the current node
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
      * @param int          $recursionLevel
71 71
      *
72 72
      */
73
-    protected function extractTuFromNode( DOMNode $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0 ) {
73
+    protected function extractTuFromNode(DOMNode $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0) {
74 74
 
75
-        if ( $childNode->nodeType != XML_ELEMENT_NODE ) {
75
+        if ($childNode->nodeType != XML_ELEMENT_NODE) {
76 76
             return;
77 77
         }
78 78
 
79
-        if ( $childNode->nodeName === 'group' ) {
79
+        if ($childNode->nodeName === 'group') {
80 80
 
81 81
             // add nested context-groups
82
-            foreach ( $childNode->childNodes as $nestedChildNode ) {
83
-                if ( $nestedChildNode->nodeName === 'context-group' ) {
82
+            foreach ($childNode->childNodes as $nestedChildNode) {
83
+                if ($nestedChildNode->nodeName === 'context-group') {
84 84
                     $contextGroups[] = $nestedChildNode;
85 85
                 }
86 86
             }
@@ -88,23 +88,23 @@  discard block
 block discarded – undo
88 88
             // avoid infinite recursion
89 89
             $recursionLevel++;
90 90
 
91
-            foreach ( $childNode->childNodes as $nestedChildNode ) {
91
+            foreach ($childNode->childNodes as $nestedChildNode) {
92 92
 
93 93
                 // nested groups
94
-                if ( $nestedChildNode->nodeName === 'group' ) {
94
+                if ($nestedChildNode->nodeName === 'group') {
95 95
 
96
-                    if ( $recursionLevel < self::MAX_GROUP_RECURSION_LEVEL ) {
97
-                        $this->extractTuFromNode( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel );
96
+                    if ($recursionLevel < self::MAX_GROUP_RECURSION_LEVEL) {
97
+                        $this->extractTuFromNode($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel);
98 98
                     } else {
99
-                        throw new OverflowException( "Maximum tag group nesting level of '" . self::MAX_GROUP_RECURSION_LEVEL . "' reached, aborting!" );
99
+                        throw new OverflowException("Maximum tag group nesting level of '" . self::MAX_GROUP_RECURSION_LEVEL . "' reached, aborting!");
100 100
                     }
101 101
 
102
-                } elseif ( $nestedChildNode->nodeName === $this->getTuTagName() ) {
103
-                    $this->extractTransUnit( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups );
102
+                } elseif ($nestedChildNode->nodeName === $this->getTuTagName()) {
103
+                    $this->extractTransUnit($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups);
104 104
                 }
105 105
             }
106
-        } elseif ( $childNode->nodeName === $this->getTuTagName() ) {
107
-            $this->extractTransUnit( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups );
106
+        } elseif ($childNode->nodeName === $this->getTuTagName()) {
107
+            $this->extractTransUnit($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups);
108 108
         }
109 109
     }
110 110
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      *
122 122
      * @return mixed
123 123
      */
124
-    abstract protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] );
124
+    abstract protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []);
125 125
 
126 126
     /**
127 127
      * @param DOMDocument $dom
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return array
131 131
      */
132
-    protected function extractContent( DOMDocument $dom, DOMNode $node ) {
132
+    protected function extractContent(DOMDocument $dom, DOMNode $node) {
133 133
         return [
134
-                'raw-content' => $this->extractTagContent( $dom, $node ),
135
-                'attr'        => $this->extractTagAttributes( $node )
134
+                'raw-content' => $this->extractTagContent($dom, $node),
135
+                'attr'        => $this->extractTagAttributes($node)
136 136
         ];
137 137
     }
138 138
 
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
      *
150 150
      * @return array
151 151
      */
152
-    protected function extractTagAttributes( DOMNode $element ) {
152
+    protected function extractTagAttributes(DOMNode $element) {
153 153
         $tagAttributes = [];
154 154
 
155
-        if ( $element->hasAttributes() ) {
156
-            foreach ( $element->attributes as $attr ) {
157
-                $tagAttributes[ $attr->nodeName ] = $attr->nodeValue;
155
+        if ($element->hasAttributes()) {
156
+            foreach ($element->attributes as $attr) {
157
+                $tagAttributes[$attr->nodeName] = $attr->nodeValue;
158 158
             }
159 159
         }
160 160
 
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @return string
171 171
      */
172
-    protected function extractTagContent( DOMDocument $dom, DOMNode $element ) {
172
+    protected function extractTagContent(DOMDocument $dom, DOMNode $element) {
173 173
         $childNodes       = $element->hasChildNodes();
174 174
         $extractedContent = '';
175 175
 
176
-        if ( !empty( $childNodes ) ) {
177
-            foreach ( $element->childNodes as $node ) {
178
-                $extractedContent .= Emoji::toEntity( Strings::fixNonWellFormedXml( $dom->saveXML( $node ) ) );
176
+        if (!empty($childNodes)) {
177
+            foreach ($element->childNodes as $node) {
178
+                $extractedContent .= Emoji::toEntity(Strings::fixNonWellFormedXml($dom->saveXML($node)));
179 179
             }
180 180
         }
181 181
 
182
-        return str_replace( Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent );
182
+        return str_replace(Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent);
183 183
     }
184 184
 
185 185
     /**
@@ -190,45 +190,45 @@  discard block
 block discarded – undo
190 190
      *
191 191
      * @return array
192 192
      */
193
-    protected function extractContentWithMarksAndExtTags( DOMDocument $dom, DOMElement $childNode ) {
193
+    protected function extractContentWithMarksAndExtTags(DOMDocument $dom, DOMElement $childNode) {
194 194
         $source = [];
195 195
 
196 196
         // example:
197 197
         // <g id="1"><mrk mid="0" mtype="seg">An English string with g tags</mrk></g>
198
-        $raw = $this->extractTagContent( $dom, $childNode );
198
+        $raw = $this->extractTagContent($dom, $childNode);
199 199
 
200
-        $markers = preg_split( '#<mrk\s#si', $raw, -1 );
200
+        $markers = preg_split('#<mrk\s#si', $raw, -1);
201 201
 
202 202
         $mi = 0;
203
-        while ( isset( $markers[ $mi + 1 ] ) ) {
204
-            unset( $mid );
203
+        while (isset($markers[$mi + 1])) {
204
+            unset($mid);
205 205
 
206
-            preg_match( '|mid\s?=\s?["\'](.*?)["\']|si', $markers[ $mi + 1 ], $mid );
206
+            preg_match('|mid\s?=\s?["\'](.*?)["\']|si', $markers[$mi + 1], $mid);
207 207
 
208 208
             // if it's a Trados file the trailing spaces after </mrk> are meaningful
209 209
             // so we add them to
210 210
             $trailingSpaces = '';
211
-            if ( $this->xliffProprietary === 'trados' ) {
212
-                preg_match_all( '/<\/mrk>[\s]+/iu', $markers[ $mi + 1 ], $trailingSpacesMatches );
211
+            if ($this->xliffProprietary === 'trados') {
212
+                preg_match_all('/<\/mrk>[\s]+/iu', $markers[$mi + 1], $trailingSpacesMatches);
213 213
 
214
-                if ( isset( $trailingSpacesMatches[ 0 ] ) && count( $trailingSpacesMatches[ 0 ] ) > 0 ) {
215
-                    foreach ( $trailingSpacesMatches[ 0 ] as $match ) {
216
-                        $trailingSpaces = str_replace( '</mrk>', '', $match );
214
+                if (isset($trailingSpacesMatches[0]) && count($trailingSpacesMatches[0]) > 0) {
215
+                    foreach ($trailingSpacesMatches[0] as $match) {
216
+                        $trailingSpaces = str_replace('</mrk>', '', $match);
217 217
                     }
218 218
                 }
219 219
             }
220 220
 
221 221
             //re-build the mrk tag after the split
222
-            $originalMark = trim( '<mrk ' . $markers[ $mi + 1 ] );
222
+            $originalMark = trim('<mrk ' . $markers[$mi + 1]);
223 223
 
224
-            $mark_string  = preg_replace( '#^<mrk\s[^>]+>(.*)#', '$1', $originalMark ); // at this point we have: ---> 'Test </mrk> </g>>'
225
-            $mark_content = preg_split( '#</mrk>#si', $mark_string );
224
+            $mark_string  = preg_replace('#^<mrk\s[^>]+>(.*)#', '$1', $originalMark); // at this point we have: ---> 'Test </mrk> </g>>'
225
+            $mark_content = preg_split('#</mrk>#si', $mark_string);
226 226
 
227 227
             $sourceArray = [
228
-                    'mid'           => ( isset( $mid[ 1 ] ) ) ? $mid[ 1 ] : $mi,
229
-                    'ext-prec-tags' => ( $mi == 0 ? $markers[ 0 ] : "" ),
230
-                    'raw-content'   => ( isset( $mark_content[ 0 ] ) ) ? $mark_content[ 0 ] . $trailingSpaces : '',
231
-                    'ext-succ-tags' => ( isset( $mark_content[ 1 ] ) ) ? $mark_content[ 1 ] : '',
228
+                    'mid'           => (isset($mid[1])) ? $mid[1] : $mi,
229
+                    'ext-prec-tags' => ($mi == 0 ? $markers[0] : ""),
230
+                    'raw-content'   => (isset($mark_content[0])) ? $mark_content[0] . $trailingSpaces : '',
231
+                    'ext-succ-tags' => (isset($mark_content[1])) ? $mark_content[1] : '',
232 232
             ];
233 233
 
234 234
             $source[] = $sourceArray;
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @return array
246 246
      */
247
-    protected function getDataRefMap( $originalData ) {
247
+    protected function getDataRefMap($originalData) {
248 248
         // dataRef map
249 249
         $dataRefMap = [];
250
-        foreach ( $originalData as $datum ) {
251
-            if ( isset( $datum[ 'attr' ][ 'id' ] ) ) {
252
-                $dataRefMap[ $datum[ 'attr' ][ 'id' ] ] = $datum[ 'raw-content' ];
250
+        foreach ($originalData as $datum) {
251
+            if (isset($datum['attr']['id'])) {
252
+                $dataRefMap[$datum['attr']['id']] = $datum['raw-content'];
253 253
             }
254 254
         }
255 255
 
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return bool
263 263
      */
264
-    protected function stringContainsMarks( $raw ) {
265
-        $markers = preg_split( '#<mrk\s#si', $raw, -1 );
264
+    protected function stringContainsMarks($raw) {
265
+        $markers = preg_split('#<mrk\s#si', $raw, -1);
266 266
 
267
-        return isset( $markers[ 1 ] );
267
+        return isset($markers[1]);
268 268
     }
269 269
 
270 270
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @return array
275 275
      * @throws \Exception
276 276
      */
277
-    protected function JSONOrRawContentArray( $noteValue, $escapeStrings = true ) {
277
+    protected function JSONOrRawContentArray($noteValue, $escapeStrings = true) {
278 278
         //
279 279
         // convert double escaped entites
280 280
         //
@@ -284,17 +284,17 @@  discard block
 block discarded – undo
284 284
         // &amp;amp; ---> &amp;
285 285
         // &amp;apos ---> &apos;
286 286
         //
287
-        if ( Strings::isADoubleEscapedEntity( $noteValue ) ) {
288
-            $noteValue = Strings::htmlspecialchars_decode( $noteValue, true );
287
+        if (Strings::isADoubleEscapedEntity($noteValue)) {
288
+            $noteValue = Strings::htmlspecialchars_decode($noteValue, true);
289 289
         } else {
290 290
             // for non escaped entities $escapeStrings is always true for security reasons
291 291
             $escapeStrings = true;
292 292
         }
293 293
 
294
-        if ( Strings::isJSON( $noteValue ) ) {
295
-            return [ 'json' => Strings::cleanCDATA( $noteValue ) ];
294
+        if (Strings::isJSON($noteValue)) {
295
+            return ['json' => Strings::cleanCDATA($noteValue)];
296 296
         }
297 297
 
298
-        return [ 'raw-content' => Strings::fixNonWellFormedXml( $noteValue, $escapeStrings ) ];
298
+        return ['raw-content' => Strings::fixNonWellFormedXml($noteValue, $escapeStrings)];
299 299
     }
300 300
 }
Please login to merge, or discard this patch.
src/XliffReplacer/XliffSAXTranslationReplacer.php 1 patch
Spacing   +206 added lines, -206 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
     ];
33 33
 
34 34
     public function replaceTranslation() {
35
-        fwrite( $this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>' );
35
+        fwrite($this->outputFP, '<?xml version="1.0" encoding="UTF-8"?>');
36 36
 
37 37
         //create Sax parser
38 38
         $xmlParser = $this->initSaxParser();
39 39
 
40
-        while ( $this->currentBuffer = fread( $this->originalFP, 4096 ) ) {
40
+        while ($this->currentBuffer = fread($this->originalFP, 4096)) {
41 41
             /*
42 42
                preprocess file
43 43
              */
44 44
             // obfuscate entities because sax automatically does html_entity_decode
45
-            $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
45
+            $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
46 46
 
47 47
             //avoid cutting entities in half:
48 48
             //the last fread could have truncated an entity (say, '&lt;' in '&l'), thus invalidating the escaping
@@ -54,84 +54,84 @@  discard block
 block discarded – undo
54 54
             // add 9 Bytes and substitute the entities, if the & is present, and it is not at the end
55 55
             //it can't be an entity, exit the loop
56 56
 
57
-            while ( true ) {
58
-                $_ampPos = strpos( $temporary_check_buffer, '&' );
57
+            while (true) {
58
+                $_ampPos = strpos($temporary_check_buffer, '&');
59 59
 
60 60
                 //check for real entity or escape it to safely exit from the loop!!!
61
-                if ( $_ampPos === false || strlen( substr( $temporary_check_buffer, $_ampPos ) ) > 9 ) {
61
+                if ($_ampPos === false || strlen(substr($temporary_check_buffer, $_ampPos)) > 9) {
62 62
                     $escape_AMP = true;
63 63
                     break;
64 64
                 }
65 65
 
66 66
                 //if an entity is still present, fetch some more and repeat the escaping
67
-                $this->currentBuffer    .= fread( $this->originalFP, 9 );
68
-                $temporary_check_buffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
67
+                $this->currentBuffer .= fread($this->originalFP, 9);
68
+                $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
69 69
             }
70 70
 
71 71
             //free stuff outside the loop
72
-            unset( $temporary_check_buffer );
72
+            unset($temporary_check_buffer);
73 73
 
74
-            $this->currentBuffer = preg_replace( "/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
75
-            if ( $escape_AMP ) {
76
-                $this->currentBuffer = str_replace( "&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer );
74
+            $this->currentBuffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
75
+            if ($escape_AMP) {
76
+                $this->currentBuffer = str_replace("&", self::$INTERNAL_TAG_PLACEHOLDER . 'amp' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
77 77
             }
78 78
 
79 79
             //get length of chunk
80
-            $this->len = strlen( $this->currentBuffer );
80
+            $this->len = strlen($this->currentBuffer);
81 81
 
82 82
             //parse chunk of text
83
-            if ( !xml_parse( $xmlParser, $this->currentBuffer, feof( $this->originalFP ) ) ) {
83
+            if (!xml_parse($xmlParser, $this->currentBuffer, feof($this->originalFP))) {
84 84
                 //if unable, raise an exception
85
-                throw new RuntimeException( sprintf(
85
+                throw new RuntimeException(sprintf(
86 86
                         "XML error: %s at line %d",
87
-                        xml_error_string( xml_get_error_code( $xmlParser ) ),
88
-                        xml_get_current_line_number( $xmlParser )
89
-                ) );
87
+                        xml_error_string(xml_get_error_code($xmlParser)),
88
+                        xml_get_current_line_number($xmlParser)
89
+                ));
90 90
             }
91 91
             //get accumulated this->offset in document: as long as SAX pointer advances, we keep track of total bytes it has seen so far; this way, we can translate its global pointer in an address local to the current buffer of text to retrieve last char of tag
92 92
             $this->offset += $this->len;
93 93
         }
94 94
 
95 95
         // close Sax parser
96
-        $this->closeSaxParser( $xmlParser );
96
+        $this->closeSaxParser($xmlParser);
97 97
 
98 98
     }
99 99
 
100 100
     /**
101 101
      * @inheritDoc
102 102
      */
103
-    protected function tagOpen( $parser, $name, $attr ) {
103
+    protected function tagOpen($parser, $name, $attr) {
104 104
         // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
105
-        if ( $this->tuTagName === $name ) {
105
+        if ($this->tuTagName === $name) {
106 106
             $this->inTU = true;
107 107
 
108 108
             // get id
109 109
             // trim to first 100 characters because this is the limit on Matecat's DB
110
-            $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 );
110
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
111 111
 
112 112
             // `translate` attribute can be only yes or no
113
-            if ( isset( $attr[ 'translate' ] ) && $attr[ 'translate' ] === 'no' ) {
114
-                $attr[ 'translate' ] = 'no';
113
+            if (isset($attr['translate']) && $attr['translate'] === 'no') {
114
+                $attr['translate'] = 'no';
115 115
             } else {
116
-                $attr[ 'translate' ] = 'yes';
116
+                $attr['translate'] = 'yes';
117 117
             }
118 118
 
119 119
             // current 'translate' attribute of the current trans-unit
120
-            $this->currentTransUnitTranslate = $attr[ 'translate' ];
120
+            $this->currentTransUnitTranslate = $attr['translate'];
121 121
         }
122 122
 
123
-        if ( 'source' === $name ) {
123
+        if ('source' === $name) {
124 124
             $this->sourceAttributes = $attr;
125 125
         }
126 126
 
127
-        if ( 'mda:metadata' === $name ) {
127
+        if ('mda:metadata' === $name) {
128 128
             $this->unitContainsMda = true;
129 129
         }
130 130
 
131 131
         // check if we are entering into a <target>
132
-        if ( 'target' === $name ) {
132
+        if ('target' === $name) {
133 133
 
134
-            if ( $this->currentTransUnitTranslate === 'no' ) {
134
+            if ($this->currentTransUnitTranslate === 'no') {
135 135
                 $this->inTarget = false;
136 136
             } else {
137 137
                 $this->inTarget = true;
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 
141 141
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
142 142
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
143
-        if ( !$this->inTarget ) {
143
+        if (!$this->inTarget) {
144 144
 
145 145
             $tag = '';
146 146
 
@@ -162,8 +162,8 @@  discard block
 block discarded – undo
162 162
             //
163 163
             // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit
164 164
             //
165
-            if ( $this->xliffVersion === 2 && ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) && $this->unitContainsMda === false ) {
166
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) && !empty( $this->transUnits[ $this->currentTransUnitId ] ) && !$this->hasWrittenCounts ) {
165
+            if ($this->xliffVersion === 2 && ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && $this->unitContainsMda === false) {
166
+                if (isset($this->transUnits[$this->currentTransUnitId]) && !empty($this->transUnits[$this->currentTransUnitId]) && !$this->hasWrittenCounts) {
167 167
 
168 168
                     // we need to update counts here
169 169
                     $this->updateCounts();
@@ -180,90 +180,90 @@  discard block
 block discarded – undo
180 180
             $lastMrkState = null;
181 181
             $stateProp    = '';
182 182
 
183
-            foreach ( $attr as $k => $v ) {
183
+            foreach ($attr as $k => $v) {
184 184
 
185 185
                 //if tag name is file, we must replace the target-language attribute
186
-                if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) {
186
+                if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) {
187 187
                     //replace Target language with job language provided from constructor
188 188
                     $tag .= "$k=\"$this->targetLang\" ";
189 189
                 } else {
190 190
                     $pos = 0;
191
-                    if ( $this->currentTransUnitId and isset($this->transUnits[ $this->currentTransUnitId ])) {
192
-                        $pos = current( $this->transUnits[ $this->currentTransUnitId ] );
191
+                    if ($this->currentTransUnitId and isset($this->transUnits[$this->currentTransUnitId])) {
192
+                        $pos = current($this->transUnits[$this->currentTransUnitId]);
193 193
                     }
194 194
 
195
-                    if ( $name === $this->tuTagName and isset($this->segments[ $pos ]) and isset($this->segments[ $pos ][ 'sid' ]) ) {
195
+                    if ($name === $this->tuTagName and isset($this->segments[$pos]) and isset($this->segments[$pos]['sid'])) {
196 196
 
197
-                        $sid = $this->segments[ $pos ][ 'sid' ];
197
+                        $sid = $this->segments[$pos]['sid'];
198 198
 
199 199
                         // add `help-id` to xliff v.1*
200 200
                         // add `mtc:segment-id` to xliff v.2*
201
-                        if ( $this->xliffVersion === 1 && strpos( $tag, 'help-id' ) === false ) {
202
-                            if ( !empty( $sid ) ) {
201
+                        if ($this->xliffVersion === 1 && strpos($tag, 'help-id') === false) {
202
+                            if (!empty($sid)) {
203 203
                                 $tag .= "help-id=\"$sid\" ";
204 204
                             }
205
-                        } elseif ( $this->xliffVersion === 2 && strpos( $tag, 'mtc:segment-id' ) === false ) {
206
-                            if ( !empty( $sid ) ) {
205
+                        } elseif ($this->xliffVersion === 2 && strpos($tag, 'mtc:segment-id') === false) {
206
+                            if (!empty($sid)) {
207 207
                                 $tag .= "mtc:segment-id=\"$sid\" ";
208 208
                             }
209 209
                         }
210 210
 
211
-                    } elseif ( 'segment' === $name && $this->xliffVersion === 2 ) { // add state to segment in Xliff v2
212
-                        list( $stateProp, $lastMrkState ) = $this->setTransUnitState( $this->segments[ $pos ], $stateProp, $lastMrkState );
213
-                    } elseif ( 'target' === $name && $this->xliffVersion === 1 ) { // add state to target in Xliff v1
214
-                        list( $stateProp, $lastMrkState ) = $this->setTransUnitState( $this->segments[ $pos ], $stateProp, $lastMrkState );
211
+                    } elseif ('segment' === $name && $this->xliffVersion === 2) { // add state to segment in Xliff v2
212
+                        list($stateProp, $lastMrkState) = $this->setTransUnitState($this->segments[$pos], $stateProp, $lastMrkState);
213
+                    } elseif ('target' === $name && $this->xliffVersion === 1) { // add state to target in Xliff v1
214
+                        list($stateProp, $lastMrkState) = $this->setTransUnitState($this->segments[$pos], $stateProp, $lastMrkState);
215 215
                     }
216 216
 
217 217
                     //normal tag flux, put attributes in it
218 218
                     $tag .= "$k=\"$v\" ";
219 219
 
220 220
                     // replace state for xliff v2
221
-                    if ( $stateProp ) {
221
+                    if ($stateProp) {
222 222
                         $pattern = '/state=\"(.*)\"/i';
223
-                        $tag     = preg_replace( $pattern, $stateProp, $tag );
223
+                        $tag     = preg_replace($pattern, $stateProp, $tag);
224 224
                     }
225 225
                 }
226 226
             }
227 227
 
228 228
             // add oasis xliff 20 namespace
229
-            if ( $this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) {
229
+            if ($this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) {
230 230
                 $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"';
231 231
             }
232 232
 
233 233
             // add MateCat specific namespace, we want maybe add non-XLIFF attributes
234
-            if ( $name === 'xliff' && !array_key_exists( 'xmlns:mtc', $attr ) ) {
234
+            if ($name === 'xliff' && !array_key_exists('xmlns:mtc', $attr)) {
235 235
                 $tag .= ' xmlns:mtc="https://www.matecat.com" ';
236 236
             }
237 237
 
238 238
             // trgLang
239
-            if ( $name === 'xliff' ) {
240
-                $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag );
239
+            if ($name === 'xliff') {
240
+                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
241 241
             }
242 242
 
243 243
             //this logic helps detecting empty tags
244 244
             //get current position of SAX pointer in all the stream of data is has read so far:
245 245
             //it points at the end of current tag
246
-            $idx = xml_get_current_byte_index( $parser );
246
+            $idx = xml_get_current_byte_index($parser);
247 247
 
248 248
             //check whether the bounds of current tag are entirely in current buffer or the end of the current tag
249 249
             //is outside current buffer (in the latter case, it's in next buffer to be read by the while loop);
250 250
             //this check is necessary because we may have truncated a tag in half with current read,
251 251
             //and the other half may be encountered in the next buffer it will be passed
252
-            if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) {
252
+            if (isset($this->currentBuffer[$idx - $this->offset])) {
253 253
                 //if this tag entire lenght fitted in the buffer, the last char must be the last
254 254
                 //symbol before the '>'; if it's an empty tag, it is assumed that it's a '/'
255
-                $lastChar = $this->currentBuffer[ $idx - $this->offset ];
255
+                $lastChar = $this->currentBuffer[$idx - $this->offset];
256 256
             } else {
257 257
                 //if it's out, simple use the last character of the chunk
258
-                $lastChar = $this->currentBuffer[ $this->len - 1 ];
258
+                $lastChar = $this->currentBuffer[$this->len - 1];
259 259
             }
260 260
 
261 261
             //trim last space
262
-            $tag = rtrim( $tag );
262
+            $tag = rtrim($tag);
263 263
 
264 264
             //detect empty tag
265
-            $this->isEmpty = ( $lastChar == '/' || $name == 'x' );
266
-            if ( $this->isEmpty ) {
265
+            $this->isEmpty = ($lastChar == '/' || $name == 'x');
266
+            if ($this->isEmpty) {
267 267
                 $tag .= '/';
268 268
             }
269 269
 
@@ -271,30 +271,30 @@  discard block
 block discarded – undo
271 271
             $tag .= ">";
272 272
 
273 273
             //set a a Buffer for the segSource Source tag
274
-            if ( $this->bufferIsActive || in_array( $name, $this->nodesToCopy ) ) { // we are opening a critical CDATA section
274
+            if ($this->bufferIsActive || in_array($name, $this->nodesToCopy)) { // we are opening a critical CDATA section
275 275
 
276 276
                 //WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!!
277 277
                 //so check for isEmpty also in conjunction with name
278
-                if ( $this->isEmpty && ( 'source' === $name || 'seg-source' === $name ) ) {
279
-                    $this->postProcAndFlush( $this->outputFP, $tag );
278
+                if ($this->isEmpty && ('source' === $name || 'seg-source' === $name)) {
279
+                    $this->postProcAndFlush($this->outputFP, $tag);
280 280
                 } else {
281 281
                     //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
282 282
                     $this->bufferIsActive = true;
283
-                    $this->CDATABuffer    .= $tag;
283
+                    $this->CDATABuffer .= $tag;
284 284
                 }
285 285
             } else {
286
-                $this->postProcAndFlush( $this->outputFP, $tag );
286
+                $this->postProcAndFlush($this->outputFP, $tag);
287 287
             }
288 288
         }
289 289
 
290 290
         // update segmentPositionInTu
291 291
 
292
-        if ( $this->xliffVersion === 1 && $this->inTU && $name === 'source' ) {
292
+        if ($this->xliffVersion === 1 && $this->inTU && $name === 'source') {
293 293
             $asdasdsa = $attr;
294 294
             $this->segmentPositionInTu++;
295 295
         }
296 296
 
297
-        if ( $this->xliffVersion === 2 && $this->inTU && $name === 'segment' ) {
297
+        if ($this->xliffVersion === 2 && $this->inTU && $name === 'segment') {
298 298
             $asdasdsa = $attr;
299 299
             $this->segmentPositionInTu++;
300 300
         }
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
     /**
304 304
      * @inheritDoc
305 305
      */
306
-    protected function tagClose( $parser, $name ) {
306
+    protected function tagClose($parser, $name) {
307 307
         $tag = '';
308 308
 
309 309
         /**
@@ -312,26 +312,26 @@  discard block
 block discarded – undo
312 312
          *
313 313
          * self::tagOpen method
314 314
          */
315
-        if ( !$this->isEmpty && !( $this->inTarget && $name !== 'target' ) ) {
315
+        if (!$this->isEmpty && !($this->inTarget && $name !== 'target')) {
316 316
 
317
-            if ( !$this->inTarget ) {
317
+            if (!$this->inTarget) {
318 318
                 $tag = "</$name>";
319 319
             }
320 320
 
321
-            if ( 'target' == $name ) {
321
+            if ('target' == $name) {
322 322
 
323
-                if ( $this->currentTransUnitTranslate === 'no' ) {
323
+                if ($this->currentTransUnitTranslate === 'no') {
324 324
                     // do nothing
325
-                } elseif ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
325
+                } elseif (isset($this->transUnits[$this->currentTransUnitId])) {
326 326
 
327 327
                     // get translation of current segment, by indirect indexing: id -> positional index -> segment
328 328
                     // actually there may be more that one segment to that ID if there are two mrk of the same source segment
329 329
 
330
-                    $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
330
+                    $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
331 331
 
332 332
                     // $currentSegmentId
333
-                    if ( !empty( $listOfSegmentsIds ) ) {
334
-                        $this->setCurrentSegmentArray( $listOfSegmentsIds );
333
+                    if (!empty($listOfSegmentsIds)) {
334
+                        $this->setCurrentSegmentArray($listOfSegmentsIds);
335 335
                     }
336 336
 
337 337
                     /*
@@ -348,12 +348,12 @@  discard block
 block discarded – undo
348 348
                     $this->lastTransUnit = [];
349 349
 
350 350
                     $last_value    = null;
351
-                    $segmentsCount = count( $listOfSegmentsIds );
352
-                    for ( $i = 0; $i < $segmentsCount; $i++ ) {
353
-                        $id = $listOfSegmentsIds[ $i ];
354
-                        if ( isset( $this->segments[ $id ] ) && ( $i == 0 || $last_value + 1 == $listOfSegmentsIds[ $i ] ) ) {
355
-                            $last_value            = $listOfSegmentsIds[ $i ];
356
-                            $this->lastTransUnit[] = $this->segments[ $id ];
351
+                    $segmentsCount = count($listOfSegmentsIds);
352
+                    for ($i = 0; $i < $segmentsCount; $i++) {
353
+                        $id = $listOfSegmentsIds[$i];
354
+                        if (isset($this->segments[$id]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[$i])) {
355
+                            $last_value            = $listOfSegmentsIds[$i];
356
+                            $this->lastTransUnit[] = $this->segments[$id];
357 357
                         }
358 358
                     }
359 359
 
@@ -365,27 +365,27 @@  discard block
 block discarded – undo
365 365
                     // we must reset the lastMrkId found because this is a new segment.
366 366
                     $lastMrkId = -1;
367 367
 
368
-                    if ( $this->xliffVersion === 2 ) {
369
-                        $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ];
368
+                    if ($this->xliffVersion === 2) {
369
+                        $seg = $this->segments[$this->currentSegmentArray['sid']];
370 370
 
371 371
                         // update counts
372
-                        if ( !$this->hasWrittenCounts && !empty( $seg ) ) {
373
-                            $this->updateSegmentCounts( $seg );
372
+                        if (!$this->hasWrittenCounts && !empty($seg)) {
373
+                            $this->updateSegmentCounts($seg);
374 374
                         }
375 375
 
376 376
                         // delete translations so the prepareSegment
377 377
                         // will put source content in target tag
378
-                        if ( $this->sourceInTarget ) {
379
-                            $seg[ 'translation' ] = '';
378
+                        if ($this->sourceInTarget) {
379
+                            $seg['translation'] = '';
380 380
                             $this->resetCounts();
381 381
                         }
382 382
 
383 383
                         // append $translation
384
-                        $translation = $this->prepareTranslation( $seg, $translation );
384
+                        $translation = $this->prepareTranslation($seg, $translation);
385 385
 
386
-                        list( $stateProp, $lastMrkState ) = $this->setTransUnitState( $seg, $stateProp, $lastMrkState );
386
+                        list($stateProp, $lastMrkState) = $this->setTransUnitState($seg, $stateProp, $lastMrkState);
387 387
                     } else {
388
-                        foreach ( $listOfSegmentsIds as $pos => $id ) {
388
+                        foreach ($listOfSegmentsIds as $pos => $id) {
389 389
 
390 390
                             /*
391 391
                              * This routine works to respect the positional orders of markers.
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
                              * pre-assign zero to the new mrk if this is the first one ( in this segment )
399 399
                              * If it is null leave it NULL
400 400
                              */
401
-                            if ( (int)$this->segments[ $id ][ "mrk_id" ] < 0 && $this->segments[ $id ][ "mrk_id" ] !== null ) {
402
-                                $this->segments[ $id ][ "mrk_id" ] = 0;
401
+                            if ((int)$this->segments[$id]["mrk_id"] < 0 && $this->segments[$id]["mrk_id"] !== null) {
402
+                                $this->segments[$id]["mrk_id"] = 0;
403 403
                             }
404 404
 
405 405
                             /*
@@ -408,65 +408,65 @@  discard block
 block discarded – undo
408 408
                              * ( null <= -1 ) === true
409 409
                              * so, cast to int
410 410
                              */
411
-                            if ( (int)$this->segments[ $id ][ "mrk_id" ] <= $lastMrkId ) {
411
+                            if ((int)$this->segments[$id]["mrk_id"] <= $lastMrkId) {
412 412
                                 break;
413 413
                             }
414 414
 
415 415
                             // set $this->currentSegment
416
-                            $seg = $this->segments[ $id ];
416
+                            $seg = $this->segments[$id];
417 417
 
418 418
                             // update counts
419
-                            if ( !empty( $seg ) ) {
420
-                                $this->updateSegmentCounts( $seg );
419
+                            if (!empty($seg)) {
420
+                                $this->updateSegmentCounts($seg);
421 421
                             }
422 422
 
423 423
                             // delete translations so the prepareSegment
424 424
                             // will put source content in target tag
425
-                            if ( $this->sourceInTarget ) {
426
-                                $seg[ 'translation' ] = '';
425
+                            if ($this->sourceInTarget) {
426
+                                $seg['translation'] = '';
427 427
                                 $this->resetCounts();
428 428
                             }
429 429
 
430 430
                             // append $translation
431
-                            $translation = $this->prepareTranslation( $seg, $translation );
431
+                            $translation = $this->prepareTranslation($seg, $translation);
432 432
 
433 433
                             // for xliff 2 we need $this->transUnits[ $this->currentId ] [ $pos ] for populating metadata
434 434
 
435
-                            unset( $this->transUnits[ $this->currentTransUnitId ] [ $pos ] );
435
+                            unset($this->transUnits[$this->currentTransUnitId] [$pos]);
436 436
 
437
-                            $lastMrkId = $this->segments[ $id ][ "mrk_id" ];
437
+                            $lastMrkId = $this->segments[$id]["mrk_id"];
438 438
 
439
-                            list( $stateProp, $lastMrkState ) = $this->setTransUnitState( $seg, $stateProp, $lastMrkState );
439
+                            list($stateProp, $lastMrkState) = $this->setTransUnitState($seg, $stateProp, $lastMrkState);
440 440
                         }
441 441
                     }
442 442
 
443 443
                     //append translation
444 444
                     $targetLang = '';
445
-                    if ( $this->xliffVersion === 1 ) {
445
+                    if ($this->xliffVersion === 1) {
446 446
                         $targetLang = ' xml:lang="' . $this->targetLang . '"';
447 447
                     }
448 448
 
449
-                    $tag = $this->buildTranslateTag( $targetLang, $stateProp, $translation, $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ] );
449
+                    $tag = $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts['raw_word_count'], $this->counts['eq_word_count']);
450 450
                 }
451 451
 
452 452
                 // signal we are leaving a target
453 453
                 $this->targetWasWritten = true;
454 454
                 $this->inTarget         = false;
455
-                $this->postProcAndFlush( $this->outputFP, $tag, $treatAsCDATA = true );
456
-            } elseif ( in_array( $name, $this->nodesToCopy ) ) { // we are closing a critical CDATA section
455
+                $this->postProcAndFlush($this->outputFP, $tag, $treatAsCDATA = true);
456
+            } elseif (in_array($name, $this->nodesToCopy)) { // we are closing a critical CDATA section
457 457
 
458 458
                 $this->bufferIsActive = false;
459 459
 
460 460
                 // only for Xliff 2.*
461 461
                 // write here <mda:metaGroup> and <mda:meta> if already present in the <unit>
462
-                if ( 'mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts ) {
462
+                if ('mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts) {
463 463
 
464 464
                     // we need to update counts here
465 465
                     $this->updateCounts();
466 466
                     $this->hasWrittenCounts = true;
467 467
 
468 468
                     $tag = $this->CDATABuffer;
469
-                    $tag .= $this->getWordCountGroupForXliffV2( false );
469
+                    $tag .= $this->getWordCountGroupForXliffV2(false);
470 470
                     $tag .= "    </mda:metadata>";
471 471
 
472 472
                 } else {
@@ -476,59 +476,59 @@  discard block
 block discarded – undo
476 476
                 $this->CDATABuffer = "";
477 477
 
478 478
                 //flush to pointer
479
-                $this->postProcAndFlush( $this->outputFP, $tag );
480
-            } elseif ( 'segment' === $name ) {
479
+                $this->postProcAndFlush($this->outputFP, $tag);
480
+            } elseif ('segment' === $name) {
481 481
 
482 482
                 // only for Xliff 2.*
483 483
                 // if segment has no <target> add it BEFORE </segment>
484
-                if ( $this->xliffVersion === 2 && !$this->targetWasWritten ) {
484
+                if ($this->xliffVersion === 2 && !$this->targetWasWritten) {
485 485
 
486 486
                     $seg = $this->getCurrentSegment();
487 487
 
488 488
                     // copy attr from <source>
489 489
                     $tag = '<target';
490
-                    foreach ( $this->sourceAttributes as $k => $v ) {
490
+                    foreach ($this->sourceAttributes as $k => $v) {
491 491
                         $tag .= " $k=\"$v\"";
492 492
                     }
493 493
 
494
-                    $tag .= '>' . $seg[ 'translation' ] . '</target></segment>';
494
+                    $tag .= '>' . $seg['translation'] . '</target></segment>';
495 495
                 }
496 496
 
497
-                $this->postProcAndFlush( $this->outputFP, $tag );
497
+                $this->postProcAndFlush($this->outputFP, $tag);
498 498
 
499 499
                 // we are leaving <segment>, reset $segmentHasTarget
500 500
                 $this->targetWasWritten = false;
501 501
 
502
-            } elseif ( $name === 'trans-unit' ) {
502
+            } elseif ($name === 'trans-unit') {
503 503
 
504 504
                 // only for Xliff 1.*
505 505
                 // handling </trans-unit> closure
506
-                if ( !$this->targetWasWritten ) {
506
+                if (!$this->targetWasWritten) {
507 507
                     $seg          = $this->getCurrentSegment();
508 508
                     $lastMrkState = null;
509 509
                     $stateProp    = '';
510 510
                     $tag          = '';
511 511
 
512 512
                     // if there is translation available insert <target> BEFORE </trans-unit>
513
-                    if ( isset( $seg[ 'translation' ] ) ) {
514
-                        list( $stateProp, $lastMrkState ) = $this->setTransUnitState( $seg, $stateProp, $lastMrkState );
515
-                        $tag .= $this->createTargetTag( $seg[ 'translation' ], $stateProp );
513
+                    if (isset($seg['translation'])) {
514
+                        list($stateProp, $lastMrkState) = $this->setTransUnitState($seg, $stateProp, $lastMrkState);
515
+                        $tag .= $this->createTargetTag($seg['translation'], $stateProp);
516 516
                     }
517 517
 
518 518
                     $tag .= '</trans-unit>';
519
-                    $this->postProcAndFlush( $this->outputFP, $tag );
519
+                    $this->postProcAndFlush($this->outputFP, $tag);
520 520
                 } else {
521
-                    $this->postProcAndFlush( $this->outputFP, '</trans-unit>' );
521
+                    $this->postProcAndFlush($this->outputFP, '</trans-unit>');
522 522
                 }
523
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
523
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
524 524
                 $this->CDATABuffer .= "</$name>";
525 525
                 // Do NOT Flush
526 526
             } else { //generic tag closure do Nothing
527 527
                 // flush to pointer
528
-                $this->postProcAndFlush( $this->outputFP, $tag );
528
+                $this->postProcAndFlush($this->outputFP, $tag);
529 529
             }
530
-        } elseif ( $this->CDATABuffer === '<note/>' && $this->bufferIsActive === true ) {
531
-            $this->postProcAndFlush( $this->outputFP, '<note/>' );
530
+        } elseif ($this->CDATABuffer === '<note/>' && $this->bufferIsActive === true) {
531
+            $this->postProcAndFlush($this->outputFP, '<note/>');
532 532
             $this->bufferIsActive = false;
533 533
             $this->CDATABuffer    = '';
534 534
             $this->isEmpty        = false;
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
         }
539 539
 
540 540
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
541
-        if ( $this->tuTagName === $name ) {
541
+        if ($this->tuTagName === $name) {
542 542
             $this->currentTransUnitTranslate = null;
543 543
             $this->inTU                      = false;
544 544
             $this->segmentPositionInTu       = -1;
@@ -555,21 +555,21 @@  discard block
 block discarded – undo
555 555
      *
556 556
      * @param array $listOfSegmentsIds
557 557
      */
558
-    private function setCurrentSegmentArray( array $listOfSegmentsIds = [] ) {
558
+    private function setCurrentSegmentArray(array $listOfSegmentsIds = []) {
559 559
         // $currentSegmentId
560
-        if ( empty( $this->currentSegmentArray ) ) {
560
+        if (empty($this->currentSegmentArray)) {
561 561
             $this->currentSegmentArray = [
562
-                    'sid' => $listOfSegmentsIds[ 0 ],
562
+                    'sid' => $listOfSegmentsIds[0],
563 563
                     'tid' => $this->currentTransUnitId,
564 564
             ];
565 565
         } else {
566
-            if ( $this->currentSegmentArray[ 'tid' ] === $this->currentTransUnitId ) {
567
-                $key                                = array_search( $this->currentSegmentArray[ 'sid' ], $listOfSegmentsIds );
568
-                $this->currentSegmentArray[ 'sid' ] = $listOfSegmentsIds[ $key + 1 ];
569
-                $this->currentSegmentArray[ 'tid' ] = $this->currentTransUnitId;
566
+            if ($this->currentSegmentArray['tid'] === $this->currentTransUnitId) {
567
+                $key                                = array_search($this->currentSegmentArray['sid'], $listOfSegmentsIds);
568
+                $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key + 1];
569
+                $this->currentSegmentArray['tid'] = $this->currentTransUnitId;
570 570
             } else {
571 571
                 $this->currentSegmentArray = [
572
-                        'sid' => $listOfSegmentsIds[ 0 ],
572
+                        'sid' => $listOfSegmentsIds[0],
573 573
                         'tid' => $this->currentTransUnitId,
574 574
                 ];
575 575
             }
@@ -581,23 +581,23 @@  discard block
 block discarded – undo
581 581
      */
582 582
     private function updateCounts() {
583 583
         // populate counts
584
-        $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
584
+        $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
585 585
 
586 586
         // $currentSegmentId
587
-        if ( !empty( $listOfSegmentsIds ) ) {
588
-            $this->setCurrentSegmentArray( $listOfSegmentsIds );
587
+        if (!empty($listOfSegmentsIds)) {
588
+            $this->setCurrentSegmentArray($listOfSegmentsIds);
589 589
         }
590 590
 
591
-        if ( $this->xliffVersion === 2 ) {
592
-            $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ];
593
-            if ( !empty( $seg ) ) {
594
-                $this->updateSegmentCounts( $seg );
591
+        if ($this->xliffVersion === 2) {
592
+            $seg = $this->segments[$this->currentSegmentArray['sid']];
593
+            if (!empty($seg)) {
594
+                $this->updateSegmentCounts($seg);
595 595
             }
596 596
         } else {
597
-            foreach ( $listOfSegmentsIds as $pos => $id ) {
598
-                $seg = $this->segments[ $id ];
599
-                if ( !empty( $seg ) ) {
600
-                    $this->updateSegmentCounts( $seg );
597
+            foreach ($listOfSegmentsIds as $pos => $id) {
598
+                $seg = $this->segments[$id];
599
+                if (!empty($seg)) {
600
+                    $this->updateSegmentCounts($seg);
601 601
                 }
602 602
             }
603 603
         }
@@ -608,27 +608,27 @@  discard block
 block discarded – undo
608 608
     /**
609 609
      * @param array $seg
610 610
      */
611
-    private function updateSegmentCounts( array $seg = [] ) {
611
+    private function updateSegmentCounts(array $seg = []) {
612 612
 
613
-        $raw_word_count = $seg[ 'raw_word_count' ];
614
-        $eq_word_count = ( floor( $seg[ 'eq_word_count' ] * 100 ) / 100 );
613
+        $raw_word_count = $seg['raw_word_count'];
614
+        $eq_word_count = (floor($seg['eq_word_count'] * 100) / 100);
615 615
 
616 616
 
617
-        $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
617
+        $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
618 618
 
619
-        $this->counts[ 'segments_count_array' ][ $seg[ 'sid' ] ] = [
619
+        $this->counts['segments_count_array'][$seg['sid']] = [
620 620
             'raw_word_count' => $raw_word_count,
621 621
             'eq_word_count' => $eq_word_count,
622 622
         ];
623 623
 
624
-        $this->counts[ 'raw_word_count' ] += $raw_word_count;
625
-        $this->counts[ 'eq_word_count' ]  += $eq_word_count;
624
+        $this->counts['raw_word_count'] += $raw_word_count;
625
+        $this->counts['eq_word_count']  += $eq_word_count;
626 626
     }
627 627
 
628 628
     private function resetCounts() {
629
-        $this->counts[ 'segments_count_array' ] = [];
630
-        $this->counts[ 'raw_word_count' ] = 0;
631
-        $this->counts[ 'eq_word_count' ]  = 0;
629
+        $this->counts['segments_count_array'] = [];
630
+        $this->counts['raw_word_count'] = 0;
631
+        $this->counts['eq_word_count']  = 0;
632 632
     }
633 633
 
634 634
     /**
@@ -639,38 +639,38 @@  discard block
 block discarded – undo
639 639
      *
640 640
      * @return string
641 641
      */
642
-    protected function prepareTranslation( $seg, $transUnitTranslation = "" ) {
642
+    protected function prepareTranslation($seg, $transUnitTranslation = "") {
643 643
         $endTags = "";
644 644
 
645
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
646
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
647
-        $dataRefMap  = ( isset( $seg[ 'data_ref_map' ] ) && $seg[ 'data_ref_map' ] !== null ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : [];
645
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
646
+        $translation = Strings::removeDangerousChars($seg ['translation']);
647
+        $dataRefMap  = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : [];
648 648
 
649
-        if ( is_null( $seg [ 'translation' ] ) || $seg [ 'translation' ] == '' ) {
649
+        if (is_null($seg ['translation']) || $seg ['translation'] == '') {
650 650
             $translation = $segment;
651 651
         } else {
652
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
652
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
653 653
                 $error = (!empty($seg['error'])) ? $seg['error'] : null;
654
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) {
654
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) {
655 655
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
656 656
                 }
657 657
             }
658 658
         }
659 659
 
660 660
         // for xliff v2 we ignore the marks on purpose
661
-        if ( $this->xliffVersion === 2 ) {
661
+        if ($this->xliffVersion === 2) {
662 662
             return $translation;
663 663
         }
664 664
 
665
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
666
-            if ( $this->targetLang === 'ja-JP' ) {
667
-                $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] );
665
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
666
+            if ($this->targetLang === 'ja-JP') {
667
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
668 668
             }
669 669
 
670
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>";
670
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
671 671
         }
672 672
 
673
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . $seg[ 'succ_tags' ];
673
+        $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . $seg['succ_tags'];
674 674
 
675 675
         return $transUnitTranslation;
676 676
     }
@@ -684,15 +684,15 @@  discard block
 block discarded – undo
684 684
      *
685 685
      * @return string
686 686
      */
687
-    private function buildTranslateTag( $targetLang, $stateProp, $translation, $rawWordCount, $eqWordCount ) {
688
-        switch ( $this->xliffVersion ) {
687
+    private function buildTranslateTag($targetLang, $stateProp, $translation, $rawWordCount, $eqWordCount) {
688
+        switch ($this->xliffVersion) {
689 689
             case 1:
690 690
             default:
691 691
                 $tag = "<target $targetLang $stateProp>$translation</target>";
692 692
 
693 693
                 // if it's a Trados file don't append count group
694
-                if ( get_class( $this ) !== SdlXliffSAXTranslationReplacer::class ) {
695
-                    $tag .= $this->getWordCountGroup( $rawWordCount, $eqWordCount );
694
+                if (get_class($this) !== SdlXliffSAXTranslationReplacer::class) {
695
+                    $tag .= $this->getWordCountGroup($rawWordCount, $eqWordCount);
696 696
                 }
697 697
 
698 698
                 return $tag;
@@ -708,7 +708,7 @@  discard block
 block discarded – undo
708 708
      *
709 709
      * @return string
710 710
      */
711
-    private function getWordCountGroup( $raw_word_count, $eq_word_count ) {
711
+    private function getWordCountGroup($raw_word_count, $eq_word_count) {
712 712
         return "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">$raw_word_count</count><count count-type=\"x-matecat-weighted\">$eq_word_count</count></count-group>";
713 713
     }
714 714
 
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
      * @return array
717 717
      */
718 718
     private function getCurrentSegment() {
719
-        if ( $this->currentTransUnitTranslate === 'yes' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
720
-            $index = $this->transUnits[ $this->currentTransUnitId ][ $this->segmentPositionInTu ];
719
+        if ($this->currentTransUnitTranslate === 'yes' && isset($this->transUnits[$this->currentTransUnitId])) {
720
+            $index = $this->transUnits[$this->currentTransUnitId][$this->segmentPositionInTu];
721 721
 
722
-            if ( isset( $this->segments[ $index ] ) ) {
723
-                return $this->segments[ $index ];
722
+            if (isset($this->segments[$index])) {
723
+                return $this->segments[$index];
724 724
             }
725 725
         }
726 726
 
@@ -735,10 +735,10 @@  discard block
 block discarded – undo
735 735
      *
736 736
      * @return string
737 737
      */
738
-    private function createTargetTag( $translation, $stateProp ) {
738
+    private function createTargetTag($translation, $stateProp) {
739 739
         $targetLang = 'xml:lang="' . $this->targetLang . '"';
740 740
 
741
-        return $this->buildTranslateTag( $targetLang, $stateProp, $translation, $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ] );
741
+        return $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts['raw_word_count'], $this->counts['eq_word_count']);
742 742
     }
743 743
 
744 744
     /**
@@ -746,10 +746,10 @@  discard block
 block discarded – undo
746 746
      *
747 747
      * @return string
748 748
      */
749
-    private function getWordCountGroupForXliffV2( $withMetadataTag = true ) {
749
+    private function getWordCountGroupForXliffV2($withMetadataTag = true) {
750 750
 
751 751
         $this->mdaGroupCounter++;
752
-        $segments_count_array = $this->counts[ 'segments_count_array' ];
752
+        $segments_count_array = $this->counts['segments_count_array'];
753 753
 
754 754
         $id = $this->currentSegmentArray;
755 755
 
@@ -757,23 +757,23 @@  discard block
 block discarded – undo
757 757
 
758 758
         $return = '';
759 759
 
760
-        if ( $withMetadataTag === true ) {
760
+        if ($withMetadataTag === true) {
761 761
             $return .= '<mda:metadata>';
762 762
         }
763 763
 
764 764
         $index = 0;
765
-        foreach ($segments_count_array as $segments_count_item){
765
+        foreach ($segments_count_array as $segments_count_item) {
766 766
 
767
-            $id = 'word_count_tu['. $this->currentTransUnitId . '][' . $index.']';
767
+            $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']';
768 768
             $index++;
769 769
 
770 770
             $return .= "    <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\">
771
-                                <mda:meta type=\"x-matecat-raw\">". $segments_count_item['raw_word_count']."</mda:meta>
772
-                                <mda:meta type=\"x-matecat-weighted\">". $segments_count_item['eq_word_count']."</mda:meta>
771
+                                <mda:meta type=\"x-matecat-raw\">". $segments_count_item['raw_word_count'] . "</mda:meta>
772
+                                <mda:meta type=\"x-matecat-weighted\">". $segments_count_item['eq_word_count'] . "</mda:meta>
773 773
                             </mda:metaGroup>";
774 774
         }
775 775
 
776
-        if ( $withMetadataTag === true ) {
776
+        if ($withMetadataTag === true) {
777 777
             $return .= '</mda:metadata>';
778 778
         }
779 779
 
@@ -788,17 +788,17 @@  discard block
 block discarded – undo
788 788
      *
789 789
      * @return array
790 790
      */
791
-    private function setTransUnitState( $seg, $state_prop, $lastMrkState ) {
792
-        switch ( $seg[ 'status' ] ) {
791
+    private function setTransUnitState($seg, $state_prop, $lastMrkState) {
792
+        switch ($seg['status']) {
793 793
 
794 794
             case TranslationStatus::STATUS_FIXED:
795 795
             case TranslationStatus::STATUS_APPROVED:
796
-                if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) {
796
+                if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED) {
797 797
 
798
-                    if( isset($seg[ 'r2' ]) and $seg[ 'r2' ] == 1 ){
798
+                    if (isset($seg['r2']) and $seg['r2'] == 1) {
799 799
                         $state_prop   = "state=\"final\"";
800 800
                     } else {
801
-                        $state_prop   = ( $this->xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\"";
801
+                        $state_prop   = ($this->xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\"";
802 802
                     }
803 803
 
804 804
                     $lastMrkState = TranslationStatus::STATUS_APPROVED;
@@ -806,7 +806,7 @@  discard block
 block discarded – undo
806 806
                 break;
807 807
 
808 808
             case TranslationStatus::STATUS_TRANSLATED:
809
-                if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) {
809
+                if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED) {
810 810
                     $state_prop   = "state=\"translated\"";
811 811
                     $lastMrkState = TranslationStatus::STATUS_TRANSLATED;
812 812
                 }
@@ -814,22 +814,22 @@  discard block
 block discarded – undo
814 814
 
815 815
             case TranslationStatus::STATUS_REJECTED:  // if there is a mark REJECTED and there is not a DRAFT, all the trans-unit is REJECTED. In V2 there is no way to mark
816 816
             case TranslationStatus::STATUS_REBUTTED:
817
-                if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) {
818
-                    $state_prop   = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\"";
817
+                if (($lastMrkState == null) || ($lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT)) {
818
+                    $state_prop   = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\"";
819 819
                     $lastMrkState = TranslationStatus::STATUS_REJECTED;
820 820
                 }
821 821
                 break;
822 822
 
823 823
             case TranslationStatus::STATUS_NEW:
824
-                if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) {
825
-                    $state_prop   = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"";
824
+                if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_NEW) {
825
+                    $state_prop   = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"";
826 826
                     $lastMrkState = TranslationStatus::STATUS_NEW;
827 827
                 }
828 828
                 break;
829 829
 
830 830
             case TranslationStatus::STATUS_DRAFT:
831
-                if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) {
832
-                    $state_prop   = ( $this->xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"";
831
+                if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_DRAFT) {
832
+                    $state_prop   = ($this->xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"";
833 833
                     $lastMrkState = TranslationStatus::STATUS_DRAFT;
834 834
                 }
835 835
                 break;
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
                 // this is the case when a segment is not showed in cattool, so the row in
839 839
                 // segment_translations does not exists and
840 840
                 // ---> $seg[ 'status' ] is NULL
841
-                if ( $lastMrkState == null ) { //this is the first MRK ID
841
+                if ($lastMrkState == null) { //this is the first MRK ID
842 842
                     $state_prop   = "state=\"translated\"";
843 843
                     $lastMrkState = TranslationStatus::STATUS_TRANSLATED;
844 844
                 } else {
@@ -847,17 +847,17 @@  discard block
 block discarded – undo
847 847
                 break;
848 848
         }
849 849
 
850
-        return [ $state_prop, $lastMrkState ];
850
+        return [$state_prop, $lastMrkState];
851 851
     }
852 852
 
853 853
     /**
854 854
      * @inheritDoc
855 855
      */
856
-    protected function characterData( $parser, $data ) {
856
+    protected function characterData($parser, $data) {
857 857
         // don't write <target> data
858
-        if ( !$this->inTarget && !$this->bufferIsActive ) {
859
-            $this->postProcAndFlush( $this->outputFP, $data );
860
-        } elseif ( $this->bufferIsActive ) {
858
+        if (!$this->inTarget && !$this->bufferIsActive) {
859
+            $this->postProcAndFlush($this->outputFP, $data);
860
+        } elseif ($this->bufferIsActive) {
861 861
             $this->CDATABuffer .= $data;
862 862
         }
863 863
     }
Please login to merge, or discard this patch.