Passed
Push — master ( e8c874...e40a60 )
by Domenico
03:39 queued 12s
created
src/XliffParser/XliffParserV2.php 1 patch
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -17,17 +17,17 @@  discard block
 block discarded – undo
17 17
      * @inheritDoc
18 18
      * @throws \Exception
19 19
      */
20
-    public function parse( DOMDocument $dom, $output = [])
20
+    public function parse(DOMDocument $dom, $output = [])
21 21
     {
22 22
         $i = 1;
23 23
         /** @var DOMElement $file */
24 24
         foreach ($dom->getElementsByTagName('file') as $file) {
25 25
 
26 26
             // metadata
27
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata($dom);
27
+            $output['files'][$i]['attr'] = $this->extractMetadata($dom);
28 28
 
29 29
             // notes
30
-            $output[ 'files' ][ $i ]['notes'] = $this->extractNotes($file);
30
+            $output['files'][$i]['notes'] = $this->extractNotes($file);
31 31
 
32 32
             // trans-units
33 33
             $transUnitIdArrayForUniquenessCheck = [];
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return array
57 57
      */
58
-    private function extractMetadata( DOMDocument $dom)
58
+    private function extractMetadata(DOMDocument $dom)
59 59
     {
60 60
         $metadata = [];
61 61
 
@@ -63,16 +63,16 @@  discard block
 block discarded – undo
63 63
         $fileNode = $dom->getElementsByTagName('file')->item(0);
64 64
 
65 65
         // original
66
-        $metadata[ 'original' ] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name';
66
+        $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name';
67 67
 
68 68
         // source-language
69
-        $metadata[ 'source-language' ] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US';
69
+        $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US';
70 70
 
71 71
         // datatype
72 72
         // @TODO to be implemented
73 73
 
74 74
         // target-language
75
-        $metadata[ 'target-language' ] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US';
75
+        $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US';
76 76
 
77 77
         // custom MateCat x-attribute
78 78
         // @TODO to be implemented
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      * @return array
87 87
      * @throws \Exception
88 88
      */
89
-    private function extractNotes( DOMElement $file)
89
+    private function extractNotes(DOMElement $file)
90 90
     {
91 91
         $notes = [];
92 92
 
@@ -120,16 +120,16 @@  discard block
 block discarded – undo
120 120
     protected function extractTransUnit($transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j)
121 121
     {
122 122
         // metadata
123
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
123
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
124 124
 
125 125
         // notes
126 126
         // merge <notes> with key and key-note contained in metadata <mda:metaGroup>
127
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes($transUnit);
127
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit);
128 128
 
129 129
         // uuid
130
-        foreach ($output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note){
131
-            if(isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])){
132
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ]['uuid'] = $note['raw-content'];
130
+        foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) {
131
+            if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) {
132
+                $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content'];
133 133
             }
134 134
         }
135 135
 
@@ -137,14 +137,14 @@  discard block
 block discarded – undo
137 137
         // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata
138 138
         $originalData = $this->extractTransUnitOriginalData($transUnit);
139 139
         if (!empty($originalData)) {
140
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData;
140
+            $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData;
141 141
             $dataRefMap = $this->getDataRefMap($originalData);
142 142
         }
143 143
 
144 144
         // additionalTagData (exclusive for V2)
145 145
         $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit);
146 146
         if (!empty($additionalTagData)) {
147
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData;
147
+            $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData;
148 148
         }
149 149
 
150 150
         // content
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             if ($segment->nodeName === 'segment') {
169 169
 
170 170
                 // check segment id consistency
171
-                $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ];
171
+                $attr = $output['files'][$i]['trans-units'][$j]['attr'];
172 172
                 $this->checkSegmentIdConsistency($segment, $attr);
173 173
 
174 174
                 // loop <segment> to get nested <source> and <target> tag
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
                                 'mid'           => count($segSource) > 0 ? count($segSource) : 0,
194 194
                                 'ext-prec-tags' => '',
195 195
                                 'raw-content'   => $extractedSource['raw-content'],
196
-                                'replaced-content'   => (!empty($originalData)) ?  (new DataRefReplacer($dataRefMap))->replace($extractedSource['raw-content']) : null,
196
+                                'replaced-content'   => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedSource['raw-content']) : null,
197 197
                                 'ext-succ-tags' => '',
198 198
                             ];
199 199
                         }
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
                                 'mid'           => count($segTarget) > 0 ? count($segTarget) : 0,
220 220
                                 'ext-prec-tags' => '',
221 221
                                 'raw-content'   => $extractedTarget['raw-content'],
222
-                                'replaced-content' => (!empty($originalData)) ?  (new DataRefReplacer($dataRefMap))->replace($extractedTarget['raw-content']) : null,
222
+                                'replaced-content' => (!empty($originalData)) ? (new DataRefReplacer($dataRefMap))->replace($extractedTarget['raw-content']) : null,
223 223
                                 'ext-succ-tags' => '',
224 224
                             ];
225 225
                         }
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
             }
231 231
         }
232 232
 
233
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $source;
234
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $target;
235
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource;
236
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget;
233
+        $output['files'][$i]['trans-units'][$j]['source'] = $source;
234
+        $output['files'][$i]['trans-units'][$j]['target'] = $target;
235
+        $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource;
236
+        $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget;
237 237
 
238 238
         $j++;
239 239
     }
@@ -244,7 +244,7 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @return array
246 246
      */
247
-    private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck)
247
+    private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck)
248 248
     {
249 249
         $metadata = [];
250 250
 
@@ -255,31 +255,31 @@  discard block
 block discarded – undo
255 255
 
256 256
         $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
257 257
 
258
-        if(strlen($id) > 100){
258
+        if (strlen($id) > 100) {
259 259
             throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
260 260
         }
261 261
 
262 262
         $transUnitIdArrayForUniquenessCheck[] = $id;
263
-        $metadata[ 'id' ] = $id;
263
+        $metadata['id'] = $id;
264 264
 
265 265
         // translate
266 266
         if (null !== $transUnit->attributes->getNamedItem('translate')) {
267
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
267
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
268 268
         }
269 269
 
270 270
         // tGroupBegin
271 271
         if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) {
272
-            $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
272
+            $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
273 273
         }
274 274
 
275 275
         // tGroupEnd
276 276
         if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) {
277
-            $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
277
+            $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
278 278
         }
279 279
 
280 280
         // sizeRestriction
281
-        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') &&  '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue ) {
282
-            $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
281
+        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) {
282
+            $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
283 283
         }
284 284
 
285 285
         return $metadata;
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
      * @return array
292 292
      * @throws \Exception
293 293
      */
294
-    private function extractTransUnitOriginalData( DOMElement $transUnit)
294
+    private function extractTransUnitOriginalData(DOMElement $transUnit)
295 295
     {
296 296
         $originalData = [];
297 297
 
@@ -299,11 +299,11 @@  discard block
 block discarded – undo
299 299
         foreach ($transUnit->childNodes as $childNode) {
300 300
             if ($childNode->nodeName === 'originalData') {
301 301
                 foreach ($childNode->childNodes as $data) {
302
-                    if (null!== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
302
+                    if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
303 303
                         $dataId = $data->attributes->getNamedItem('id')->nodeValue;
304 304
 
305 305
                         $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue);
306
-                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER,'\n', $dataValue);
306
+                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue);
307 307
                         $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue);
308 308
 
309 309
                         if ('' !== $dataValue) {
@@ -311,12 +311,12 @@  discard block
 block discarded – undo
311 311
                             $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false);
312 312
 
313 313
                             // restore xliff tags
314
-                            if (isset($jsonOrRawContentArray['json'])){
315
-                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;','&gt;'], $jsonOrRawContentArray['json']);
314
+                            if (isset($jsonOrRawContentArray['json'])) {
315
+                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['json']);
316 316
                             }
317 317
 
318
-                            if (isset($jsonOrRawContentArray['raw-content'])){
319
-                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;','&gt;'], $jsonOrRawContentArray['raw-content']);
318
+                            if (isset($jsonOrRawContentArray['raw-content'])) {
319
+                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['raw-content']);
320 320
                             }
321 321
 
322 322
                             $originalData[] = array_merge(
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      *
342 342
      * @return array
343 343
      */
344
-    private function extractTransUnitAdditionalTagData( DOMElement $transUnit)
344
+    private function extractTransUnitAdditionalTagData(DOMElement $transUnit)
345 345
     {
346 346
         $additionalTagData = [];
347 347
 
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
 
354 354
                     // id
355 355
                     if ($data->nodeName === 'memsource:tag') {
356
-                        if (null!== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
356
+                        if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
357 357
                             $dataId = $data->attributes->getNamedItem('id')->nodeValue;
358 358
                             $dataArray['attr']['id'] = $dataId;
359 359
                         }
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
 
362 362
                     // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0
363 363
                     // PHP 5.6 check: in php 5.6 $data->childNodes can be null
364
-                    if( $data->childNodes != null ){
364
+                    if ($data->childNodes != null) {
365 365
 
366 366
                         // content
367 367
                         foreach ($data->childNodes as $datum) {
@@ -392,12 +392,12 @@  discard block
 block discarded – undo
392 392
      * @param DOMElement $segment
393 393
      * @param array $attr
394 394
      */
395
-    private function checkSegmentIdConsistency( DOMElement $segment, array $attr)
395
+    private function checkSegmentIdConsistency(DOMElement $segment, array $attr)
396 396
     {
397
-        if (isset($attr[ 'tGroupBegin' ]) && isset($attr[ 'tGroupEnd' ]) && $segment->attributes->getNamedItem('id')) {
397
+        if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) {
398 398
             $id = $segment->attributes->getNamedItem('id')->nodeValue;
399
-            $min = (int)$attr[ 'tGroupBegin' ];
400
-            $max = (int)$attr[ 'tGroupEnd' ];
399
+            $min = (int)$attr['tGroupBegin'];
400
+            $max = (int)$attr['tGroupEnd'];
401 401
 
402 402
             if (false === (($min <= $id) && ($id <= $max))) {
403 403
                 if ($this->logger) {
@@ -413,7 +413,7 @@  discard block
 block discarded – undo
413 413
      * @return array
414 414
      * @throws \Exception
415 415
      */
416
-    private function extractTransUnitNotes( DOMElement $transUnit)
416
+    private function extractTransUnitNotes(DOMElement $transUnit)
417 417
     {
418 418
         $notes = [];
419 419
 
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
                 foreach ($childNode->childNodes as $metadata) {
433 433
                     if ($metadata->nodeName === 'mda:metaGroup') {
434 434
                         foreach ($metadata->childNodes as $meta) {
435
-                            if (null!== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
435
+                            if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
436 436
                                 $type = $meta->attributes->getNamedItem('type')->nodeValue;
437 437
                                 $metaValue = trim($meta->nodeValue);
438 438
 
Please login to merge, or discard this patch.
src/XliffReplacer/XliffSAXTranslationReplacer.php 1 patch
Spacing   +104 added lines, -104 removed lines patch added patch discarded remove patch
@@ -17,16 +17,16 @@  discard block
 block discarded – undo
17 17
      */
18 18
     private $nodesToCopy = [
19 19
         'source',
20
-        'mda:metadata' ,
21
-        'memsource:additionalTagData' ,
22
-        'originalData' ,
23
-        'seg-source' ,
24
-        'value' ,
25
-        'bpt' ,
26
-        'ept' ,
27
-        'ph' ,
28
-        'st' ,
29
-        'note' ,
20
+        'mda:metadata',
21
+        'memsource:additionalTagData',
22
+        'originalData',
23
+        'seg-source',
24
+        'value',
25
+        'bpt',
26
+        'ept',
27
+        'ph',
28
+        'st',
29
+        'note',
30 30
         'context',
31 31
     ];
32 32
 
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
             // obfuscate entities because sax automatically does html_entity_decode
45 45
             $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
46 46
 
47
-            $lastByte = $temporary_check_buffer[ strlen($temporary_check_buffer) - 1 ];
47
+            $lastByte = $temporary_check_buffer[strlen($temporary_check_buffer) - 1];
48 48
 
49 49
             //avoid cutting entities in half:
50 50
             //the last fread could have truncated an entity (say, '&lt;' in '&l'), thus invalidating the escaping
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 }
67 67
 
68 68
                 //if an entity is still present, fetch some more and repeat the escaping
69
-                $this->currentBuffer    .= fread($this->originalFP, 9);
69
+                $this->currentBuffer .= fread($this->originalFP, 9);
70 70
                 $temporary_check_buffer = preg_replace("/&(.*?);/", self::$INTERNAL_TAG_PLACEHOLDER . '$1' . self::$INTERNAL_TAG_PLACEHOLDER, $this->currentBuffer);
71 71
             }
72 72
 
@@ -110,31 +110,31 @@  discard block
 block discarded – undo
110 110
 
111 111
             // get id
112 112
             // trim to first 100 characters because this is the limit on Matecat's DB
113
-            $this->currentTransUnitId = substr($attr[ 'id' ], 0, 100);
113
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
114 114
 
115 115
             // `translate` attribute can be only yes or no
116
-            if(isset($attr[ 'translate' ]) && $attr[ 'translate' ] === 'no'){
117
-                $attr[ 'translate' ] = 'no';
116
+            if (isset($attr['translate']) && $attr['translate'] === 'no') {
117
+                $attr['translate'] = 'no';
118 118
             } else {
119
-                $attr[ 'translate' ] = 'yes';
119
+                $attr['translate'] = 'yes';
120 120
             }
121 121
 
122 122
             // current 'translate' attribute of the current trans-unit
123
-            $this->currentTransUnitTranslate = $attr[ 'translate' ];
123
+            $this->currentTransUnitTranslate = $attr['translate'];
124 124
         }
125 125
 
126
-        if('source' === $name){
126
+        if ('source' === $name) {
127 127
             $this->sourceAttributes = $attr;
128 128
         }
129 129
 
130
-        if('mda:metadata' === $name){
130
+        if ('mda:metadata' === $name) {
131 131
             $this->unitContainsMda = true;
132 132
         }
133 133
 
134 134
         // check if we are entering into a <target>
135 135
         if ('target' === $name) {
136 136
 
137
-            if($this->currentTransUnitTranslate === 'no'){
137
+            if ($this->currentTransUnitTranslate === 'no') {
138 138
                 $this->inTarget = false;
139 139
             } else {
140 140
                 $this->inTarget = true;
@@ -165,14 +165,14 @@  discard block
 block discarded – undo
165 165
             //
166 166
             // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit
167 167
             //
168
-            if($this->xliffVersion === 2 && ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && $this->unitContainsMda === false ){
169
-                if (isset($this->transUnits[ $this->currentTransUnitId ]) && !empty($this->transUnits[ $this->currentTransUnitId ]) && !$this->unitContainsMda && !$this->hasWrittenCounts) {
168
+            if ($this->xliffVersion === 2 && ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && $this->unitContainsMda === false) {
169
+                if (isset($this->transUnits[$this->currentTransUnitId]) && !empty($this->transUnits[$this->currentTransUnitId]) && !$this->unitContainsMda && !$this->hasWrittenCounts) {
170 170
 
171 171
                     // we need to update counts here
172 172
                     $this->updateCounts();
173 173
                     $this->hasWrittenCounts = true;
174 174
 
175
-                    $tag .= $this->getWordCountGroupForXliffV2($this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ]);
175
+                    $tag .= $this->getWordCountGroupForXliffV2($this->counts['raw_word_count'], $this->counts['eq_word_count']);
176 176
                     $this->unitContainsMda = true;
177 177
                 }
178 178
             }
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
             $tag .= "<$name ";
182 182
 
183 183
             $lastMrkState = null;
184
-            $stateProp   = '';
184
+            $stateProp = '';
185 185
 
186 186
             foreach ($attr as $k => $v) {
187 187
 
@@ -192,27 +192,27 @@  discard block
 block discarded – undo
192 192
                 } else {
193 193
                     $pos = 0;
194 194
                     if ($this->currentTransUnitId) {
195
-                        $pos = current($this->transUnits[ $this->currentTransUnitId ]);
195
+                        $pos = current($this->transUnits[$this->currentTransUnitId]);
196 196
                     }
197 197
 
198 198
                     if ($name === $this->tuTagName) {
199 199
 
200
-                        $sid = $this->segments[ $pos ][ 'sid' ];
200
+                        $sid = $this->segments[$pos]['sid'];
201 201
 
202 202
                         // add `help-id` to xliff v.1*
203 203
                         // add `mtc:segment-id` to xliff v.2*
204
-                        if($this->xliffVersion === 1 && strpos($tag, 'help-id') === false){
204
+                        if ($this->xliffVersion === 1 && strpos($tag, 'help-id') === false) {
205 205
                             if (!empty($sid)) {
206 206
                                 $tag .= "help-id=\"$sid\" ";
207 207
                             }
208
-                        } elseif($this->xliffVersion === 2 && strpos($tag, 'mtc:segment-id') === false) {
208
+                        } elseif ($this->xliffVersion === 2 && strpos($tag, 'mtc:segment-id') === false) {
209 209
                             if (!empty($sid)) {
210 210
                                 $tag .= "mtc:segment-id=\"$sid\" ";
211 211
                             }
212 212
                         }
213 213
 
214 214
                     } elseif ('segment' === $name && $this->xliffVersion === 2) { // add state to segment in Xliff v2
215
-                        [$stateProp, $lastMrkState] = $this->setTransUnitState($this->segments[ $pos ], $stateProp, $lastMrkState);
215
+                        [$stateProp, $lastMrkState] = $this->setTransUnitState($this->segments[$pos], $stateProp, $lastMrkState);
216 216
                     }
217 217
 
218 218
                     //normal tag flux, put attributes in it
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 
239 239
             // trgLang
240 240
             if ($name === 'xliff') {
241
-                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="'.$this->targetLang.'"', $tag);
241
+                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
242 242
             }
243 243
 
244 244
             //this logic helps detecting empty tags
@@ -250,13 +250,13 @@  discard block
 block discarded – undo
250 250
             //is outside current buffer (in the latter case, it's in next buffer to be read by the while loop);
251 251
             //this check is necessary because we may have truncated a tag in half with current read,
252 252
             //and the other half may be encountered in the next buffer it will be passed
253
-            if (isset($this->currentBuffer[ $idx - $this->offset ])) {
253
+            if (isset($this->currentBuffer[$idx - $this->offset])) {
254 254
                 //if this tag entire lenght fitted in the buffer, the last char must be the last
255 255
                 //symbol before the '>'; if it's an empty tag, it is assumed that it's a '/'
256
-                $lastChar   = $this->currentBuffer[ $idx - $this->offset ];
256
+                $lastChar   = $this->currentBuffer[$idx - $this->offset];
257 257
             } else {
258 258
                 //if it's out, simple use the last character of the chunk
259
-                $lastChar   = $this->currentBuffer[ $this->len - 1 ];
259
+                $lastChar   = $this->currentBuffer[$this->len - 1];
260 260
             }
261 261
 
262 262
             //trim last space
@@ -281,7 +281,7 @@  discard block
 block discarded – undo
281 281
                 } else {
282 282
                     //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
283 283
                     $this->bufferIsActive = true;
284
-                    $this->CDATABuffer    .= $tag;
284
+                    $this->CDATABuffer .= $tag;
285 285
                 }
286 286
             } else {
287 287
                 $this->postProcAndFlush($this->outputFP, $tag);
@@ -290,11 +290,11 @@  discard block
 block discarded – undo
290 290
 
291 291
         // update segmentPositionInTu
292 292
 
293
-        if($this->xliffVersion === 1 && $this->inTU && $name === 'source'){
293
+        if ($this->xliffVersion === 1 && $this->inTU && $name === 'source') {
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
             $this->segmentPositionInTu++;
299 299
         }
300 300
     }
@@ -320,17 +320,17 @@  discard block
 block discarded – undo
320 320
 
321 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)){
333
+                    if (!empty($listOfSegmentsIds)) {
334 334
                         $this->setCurrentSegmentArray($listOfSegmentsIds);
335 335
                     }
336 336
 
@@ -349,13 +349,13 @@  discard block
 block discarded – undo
349 349
 
350 350
                     $warning       = false;
351 351
                     $last_value    = null;
352
-                    $segmentsCount = count( $listOfSegmentsIds );
352
+                    $segmentsCount = count($listOfSegmentsIds);
353 353
                     for ($i = 0; $i < $segmentsCount; $i++) {
354
-                        if (isset($listOfSegmentsIds[ $i ])) {
355
-                            $id = $listOfSegmentsIds[ $i ];
356
-                            if (isset($this->segments[ $id ]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[ $i ])) {
357
-                                $last_value            = $listOfSegmentsIds[ $i ];
358
-                                $this->lastTransUnit[] = $this->segments[ $id ];
354
+                        if (isset($listOfSegmentsIds[$i])) {
355
+                            $id = $listOfSegmentsIds[$i];
356
+                            if (isset($this->segments[$id]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[$i])) {
357
+                                $last_value            = $listOfSegmentsIds[$i];
358
+                                $this->lastTransUnit[] = $this->segments[$id];
359 359
                             }
360 360
                         } else {
361 361
                             $warning = true;
@@ -364,31 +364,31 @@  discard block
 block discarded – undo
364 364
 
365 365
                     if ($warning) {
366 366
                         if (null !== $this->logger) {
367
-                            $this->logger->warning("WARNING: PHP Notice polling. CurrentId: '" . $this->currentTransUnitId . "' - Filename: '" . $this->segments[ 0 ][ 'filename' ] . "' - First Segment: '" . $this->segments[
368
-                                    0 ][ 'sid' ] . "'");
367
+                            $this->logger->warning("WARNING: PHP Notice polling. CurrentId: '" . $this->currentTransUnitId . "' - Filename: '" . $this->segments[0]['filename'] . "' - First Segment: '" . $this->segments[
368
+                                    0]['sid'] . "'");
369 369
                         }
370 370
                     }
371 371
 
372 372
                     // init translation and state
373 373
                     $translation  = '';
374 374
                     $lastMrkState = null;
375
-                    $stateProp   = '';
375
+                    $stateProp = '';
376 376
 
377 377
                     // we must reset the lastMrkId found because this is a new segment.
378
-                    $lastMrkId      = -1;
378
+                    $lastMrkId = -1;
379 379
 
380 380
                     if ($this->xliffVersion === 2) {
381
-                        $seg = $this->segments[ $this->currentSegmentArray['sid'] ];
381
+                        $seg = $this->segments[$this->currentSegmentArray['sid']];
382 382
 
383 383
                         // update counts
384
-                        if(!$this->hasWrittenCounts && !empty($seg)){
384
+                        if (!$this->hasWrittenCounts && !empty($seg)) {
385 385
                             $this->updateSegmentCounts($seg);
386 386
                         }
387 387
 
388 388
                         // delete translations so the prepareSegment
389 389
                         // will put source content in target tag
390 390
                         if ($this->sourceInTarget) {
391
-                            $seg[ 'translation' ] = '';
391
+                            $seg['translation'] = '';
392 392
                             $this->resetCounts();
393 393
                         }
394 394
 
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
                              * pre-assign zero to the new mrk if this is the first one ( in this segment )
411 411
                              * If it is null leave it NULL
412 412
                              */
413
-                            if ((int)$this->segments[ $id ][ "mrk_id" ] < 0 && $this->segments[ $id ][ "mrk_id" ] !== null) {
414
-                                $this->segments[ $id ][ "mrk_id" ] = 0;
413
+                            if ((int)$this->segments[$id]["mrk_id"] < 0 && $this->segments[$id]["mrk_id"] !== null) {
414
+                                $this->segments[$id]["mrk_id"] = 0;
415 415
                             }
416 416
 
417 417
                             /*
@@ -420,22 +420,22 @@  discard block
 block discarded – undo
420 420
                              * ( null <= -1 ) === true
421 421
                              * so, cast to int
422 422
                              */
423
-                            if ((int)$this->segments[ $id ][ "mrk_id" ] <= $lastMrkId) {
423
+                            if ((int)$this->segments[$id]["mrk_id"] <= $lastMrkId) {
424 424
                                 break;
425 425
                             }
426 426
 
427 427
                             // set $this->currentSegment
428
-                            $seg = $this->segments[ $id ];
428
+                            $seg = $this->segments[$id];
429 429
 
430 430
                             // update counts
431
-                            if(!empty($seg)){
431
+                            if (!empty($seg)) {
432 432
                                 $this->updateSegmentCounts($seg);
433 433
                             }
434 434
 
435 435
                             // delete translations so the prepareSegment
436 436
                             // will put source content in target tag
437 437
                             if ($this->sourceInTarget) {
438
-                                $seg[ 'translation' ] = '';
438
+                                $seg['translation'] = '';
439 439
                                 $this->resetCounts();
440 440
                             }
441 441
 
@@ -444,9 +444,9 @@  discard block
 block discarded – undo
444 444
 
445 445
                             // for xliff 2 we need $this->transUnits[ $this->currentId ] [ $pos ] for populating metadata
446 446
 
447
-                            unset($this->transUnits[ $this->currentTransUnitId ] [ $pos ]);
447
+                            unset($this->transUnits[$this->currentTransUnitId] [$pos]);
448 448
 
449
-                            $lastMrkId = $this->segments[ $id ][ "mrk_id" ];
449
+                            $lastMrkId = $this->segments[$id]["mrk_id"];
450 450
 
451 451
                             [$stateProp, $lastMrkState] = $this->setTransUnitState($seg, $stateProp, $lastMrkState);
452 452
                         }
@@ -455,10 +455,10 @@  discard block
 block discarded – undo
455 455
                     //append translation
456 456
                     $targetLang = '';
457 457
                     if ($this->xliffVersion === 1) {
458
-                        $targetLang = ' xml:lang="'.$this->targetLang.'"';
458
+                        $targetLang = ' xml:lang="' . $this->targetLang . '"';
459 459
                     }
460 460
 
461
-                    $tag = $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ]);
461
+                    $tag = $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts['raw_word_count'], $this->counts['eq_word_count']);
462 462
                 }
463 463
 
464 464
                 // signal we are leaving a target
@@ -471,21 +471,21 @@  discard block
 block discarded – undo
471 471
 
472 472
                 // only for Xliff 2.*
473 473
                 // write here <mda:metaGroup> and <mda:meta> if already present in the <unit>
474
-                if('mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts){
474
+                if ('mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts) {
475 475
 
476 476
                     // we need to update counts here
477 477
                     $this->updateCounts();
478 478
                     $this->hasWrittenCounts = true;
479 479
 
480 480
                     $tag = $this->CDATABuffer;
481
-                    $tag .= $this->getWordCountGroupForXliffV2($this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ], false);
481
+                    $tag .= $this->getWordCountGroupForXliffV2($this->counts['raw_word_count'], $this->counts['eq_word_count'], false);
482 482
                     $tag .= "    </mda:metadata>";
483 483
 
484 484
                 } else {
485
-                    $tag = $this->CDATABuffer."</$name>";
485
+                    $tag = $this->CDATABuffer . "</$name>";
486 486
                 }
487 487
 
488
-                $this->CDATABuffer    = "";
488
+                $this->CDATABuffer = "";
489 489
 
490 490
                 //flush to pointer
491 491
                 $this->postProcAndFlush($this->outputFP, $tag);
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
 
494 494
                 // only for Xliff 2.*
495 495
                 // if segment has no <target> add it BEFORE </segment>
496
-                if($this->xliffVersion === 2 && !$this->targetWasWritten){
496
+                if ($this->xliffVersion === 2 && !$this->targetWasWritten) {
497 497
 
498 498
                     $seg = $this->getCurrentSegment();
499 499
 
@@ -503,7 +503,7 @@  discard block
 block discarded – undo
503 503
                         $tag .= " $k=\"$v\"";
504 504
                     }
505 505
 
506
-                    $tag .= '>'.$seg['translation'].'</target></segment>';
506
+                    $tag .= '>' . $seg['translation'] . '</target></segment>';
507 507
                 }
508 508
 
509 509
                 $this->postProcAndFlush($this->outputFP, $tag);
@@ -511,18 +511,18 @@  discard block
 block discarded – undo
511 511
                 // we are leaving <segment>, reset $segmentHasTarget
512 512
                 $this->targetWasWritten = false;
513 513
 
514
-            } elseif($name === 'trans-unit') {
514
+            } elseif ($name === 'trans-unit') {
515 515
 
516 516
                 // only for Xliff 1.*
517 517
                 // handling </trans-unit> closure
518
-                if(!$this->targetWasWritten){
518
+                if (!$this->targetWasWritten) {
519 519
                     $seg = $this->getCurrentSegment();
520 520
                     $lastMrkState = null;
521
-                    $stateProp   = '';
521
+                    $stateProp = '';
522 522
                     $tag = '';
523 523
 
524 524
                     // if there is translation available insert <target> BEFORE </trans-unit>
525
-                    if(isset($seg['translation'])){
525
+                    if (isset($seg['translation'])) {
526 526
                         [$stateProp, $lastMrkState] = $this->setTransUnitState($seg, $stateProp, $lastMrkState);
527 527
                         $tag .= $this->createTargetTag($seg['translation'], $stateProp);
528 528
                     }
@@ -576,7 +576,7 @@  discard block
 block discarded – undo
576 576
         } else {
577 577
             if ($this->currentSegmentArray['tid'] === $this->currentTransUnitId) {
578 578
                 $key = array_search($this->currentSegmentArray['sid'], $listOfSegmentsIds);
579
-                $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key+1];
579
+                $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key + 1];
580 580
                 $this->currentSegmentArray['tid'] = $this->currentTransUnitId;
581 581
             } else {
582 582
                 $this->currentSegmentArray = [
@@ -593,23 +593,23 @@  discard block
 block discarded – undo
593 593
     private function updateCounts()
594 594
     {
595 595
         // populate counts
596
-        $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
596
+        $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
597 597
 
598 598
         // $currentSegmentId
599
-        if(!empty($listOfSegmentsIds)){
599
+        if (!empty($listOfSegmentsIds)) {
600 600
             $this->setCurrentSegmentArray($listOfSegmentsIds);
601 601
         }
602 602
 
603 603
         if ($this->xliffVersion === 2) {
604
-            $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ];
605
-            if(!empty($seg)){
604
+            $seg = $this->segments[$this->currentSegmentArray['sid']];
605
+            if (!empty($seg)) {
606 606
                 $this->updateSegmentCounts($seg);
607 607
             }
608 608
         } else {
609 609
             foreach ($listOfSegmentsIds as $pos => $id) {
610
-                $seg = $this->segments[ $id ];
611
-                if(!empty($seg)){
612
-                    $this->updateSegmentCounts( $seg );
610
+                $seg = $this->segments[$id];
611
+                if (!empty($seg)) {
612
+                    $this->updateSegmentCounts($seg);
613 613
                 }
614 614
             }
615 615
         }
@@ -622,14 +622,14 @@  discard block
 block discarded – undo
622 622
      */
623 623
     private function updateSegmentCounts(array $seg = [])
624 624
     {
625
-        $this->counts[ 'raw_word_count' ] += $seg['raw_word_count'];
626
-        $this->counts[ 'eq_word_count' ] += (floor($seg[ 'eq_word_count' ] * 100) / 100);
625
+        $this->counts['raw_word_count'] += $seg['raw_word_count'];
626
+        $this->counts['eq_word_count'] += (floor($seg['eq_word_count'] * 100) / 100);
627 627
     }
628 628
 
629 629
     private function resetCounts()
630 630
     {
631
-        $this->counts[ 'raw_word_count' ] = 0;
632
-        $this->counts[ 'eq_word_count' ] = 0;
631
+        $this->counts['raw_word_count'] = 0;
632
+        $this->counts['eq_word_count'] = 0;
633 633
     }
634 634
 
635 635
     /**
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
     {
645 645
         $endTags = "";
646 646
 
647
-        $segment     = Strings::removeDangerousChars($seg [ 'segment' ]);
648
-        $translation = Strings::removeDangerousChars($seg [ 'translation' ]);
647
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
648
+        $translation = Strings::removeDangerousChars($seg ['translation']);
649 649
         $dataRefMap  = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : [];
650 650
 
651
-        if (is_null($seg [ 'translation' ]) || $seg [ 'translation' ] == '') {
651
+        if (is_null($seg ['translation']) || $seg ['translation'] == '') {
652 652
             $translation = $segment;
653 653
         } else {
654 654
             if ($this->callback) {
@@ -663,15 +663,15 @@  discard block
 block discarded – undo
663 663
             return $translation;
664 664
         }
665 665
 
666
-        if ($seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '') {
666
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
667 667
             if ($this->targetLang === 'ja-JP') {
668
-                $seg[ 'mrk_succ_tags' ] = ltrim($seg[ 'mrk_succ_tags' ]);
668
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
669 669
             }
670 670
 
671
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>";
671
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
672 672
         }
673 673
 
674
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . $seg[ 'succ_tags' ];
674
+        $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . $seg['succ_tags'];
675 675
 
676 676
         return $transUnitTranslation;
677 677
     }
@@ -693,7 +693,7 @@  discard block
 block discarded – undo
693 693
                 $tag = "<target $targetLang $stateProp>$translation</target>";
694 694
 
695 695
                 // if it's a Trados file don't append count group
696
-                if(get_class($this) !== SdlXliffSAXTranslationReplacer::class){
696
+                if (get_class($this) !== SdlXliffSAXTranslationReplacer::class) {
697 697
                     $tag .= $this->getWordCountGroup($rawWordCount, $eqWordCount);
698 698
                 }
699 699
 
@@ -720,10 +720,10 @@  discard block
 block discarded – undo
720 720
      */
721 721
     private function getCurrentSegment()
722 722
     {
723
-        if($this->currentTransUnitTranslate === 'yes' && isset($this->transUnits[$this->currentTransUnitId])){
723
+        if ($this->currentTransUnitTranslate === 'yes' && isset($this->transUnits[$this->currentTransUnitId])) {
724 724
             $index = $this->transUnits[$this->currentTransUnitId][$this->segmentPositionInTu];
725 725
 
726
-            if(isset($this->segments[$index])){
726
+            if (isset($this->segments[$index])) {
727 727
                 return $this->segments[$index];
728 728
             }
729 729
         }
@@ -741,9 +741,9 @@  discard block
 block discarded – undo
741 741
      */
742 742
     private function createTargetTag($translation, $stateProp)
743 743
     {
744
-        $targetLang = 'xml:lang="'.$this->targetLang.'"';
744
+        $targetLang = 'xml:lang="' . $this->targetLang . '"';
745 745
 
746
-        return $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ]);
746
+        return $this->buildTranslateTag($targetLang, $stateProp, $translation, $this->counts['raw_word_count'], $this->counts['eq_word_count']);
747 747
     }
748 748
 
749 749
     /**
@@ -756,10 +756,10 @@  discard block
 block discarded – undo
756 756
     private function getWordCountGroupForXliffV2($raw_word_count, $eq_word_count, $withMetadataTag = true)
757 757
     {
758 758
         $this->mdaGroupCounter++;
759
-        $id = 'word_count_tu_'. $this->mdaGroupCounter;
759
+        $id = 'word_count_tu_' . $this->mdaGroupCounter;
760 760
 
761
-        if($withMetadataTag === false){
762
-            return "    <mda:metaGroup id=\"".$id."\" category=\"row_xml_attribute\">
761
+        if ($withMetadataTag === false) {
762
+            return "    <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\">
763 763
                                 <mda:meta type=\"x-matecat-raw\">$raw_word_count</mda:meta>
764 764
                                 <mda:meta type=\"x-matecat-weighted\">$eq_word_count</mda:meta>
765 765
                             </mda:metaGroup>
@@ -767,7 +767,7 @@  discard block
 block discarded – undo
767 767
         }
768 768
 
769 769
         return "<mda:metadata>
770
-                <mda:metaGroup id=\"".$id."\" category=\"row_xml_attribute\">
770
+                <mda:metaGroup id=\"".$id . "\" category=\"row_xml_attribute\">
771 771
                     <mda:meta type=\"x-matecat-raw\">$raw_word_count</mda:meta>
772 772
                     <mda:meta type=\"x-matecat-weighted\">$eq_word_count</mda:meta>
773 773
                 </mda:metaGroup>
@@ -783,12 +783,12 @@  discard block
 block discarded – undo
783 783
      */
784 784
     private function setTransUnitState($seg, $state_prop, $lastMrkState)
785 785
     {
786
-        switch ($seg[ 'status' ]) {
786
+        switch ($seg['status']) {
787 787
 
788 788
             case TranslationStatus::STATUS_FIXED:
789 789
             case TranslationStatus::STATUS_APPROVED:
790 790
                 if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED) {
791
-                    $state_prop   = ($this->xliffVersion === 2) ? "state=\"reviewed\"": "state=\"signed-off\"";
791
+                    $state_prop   = ($this->xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\"";
792 792
                     $lastMrkState = TranslationStatus::STATUS_APPROVED;
793 793
                 }
794 794
                 break;
@@ -831,7 +831,7 @@  discard block
 block discarded – undo
831 831
                 break;
832 832
         }
833 833
 
834
-        return [ $state_prop, $lastMrkState ];
834
+        return [$state_prop, $lastMrkState];
835 835
     }
836 836
 
837 837
     /**
Please login to merge, or discard this patch.
src/XliffReplacer/SdlXliffSAXTranslationReplacer.php 1 patch
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -19,15 +19,15 @@  discard block
 block discarded – undo
19 19
 
20 20
             // get id
21 21
             // trim to first 100 characters because this is the limit on Matecat's DB
22
-            $this->currentTransUnitId = substr($attr[ 'id' ], 0, 100);
22
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
23 23
 
24 24
             // current 'translate' attribute of the current trans-unit
25
-            $this->currentTransUnitTranslate = isset($attr[ 'translate' ]) ? $attr[ 'translate' ] : 'yes';
25
+            $this->currentTransUnitTranslate = isset($attr['translate']) ? $attr['translate'] : 'yes';
26 26
         }
27 27
 
28 28
         // check if we are entering into a <target>
29 29
         if ('target' == $name) {
30
-            if($this->currentTransUnitTranslate === 'no'){
30
+            if ($this->currentTransUnitTranslate === 'no') {
31 31
                 $this->inTarget = false;
32 32
             } else {
33 33
                 $this->inTarget = true;
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
                 } elseif ('sdl:seg' == $name) {
65 65
 
66 66
                     // write the confidence level for this segment ( Translated, Draft, etc. )
67
-                    if (isset($this->segments[ 'matecat|' . $this->currentTransUnitId ]) && $_sdlStatus_confWritten == false) {
67
+                    if (isset($this->segments['matecat|' . $this->currentTransUnitId]) && $_sdlStatus_confWritten == false) {
68 68
 
69 69
                         // append definition attribute
70
-                        $tag .= $this->prepareTargetStatuses($this->lastTransUnit[ $this->markerPos ]);
70
+                        $tag .= $this->prepareTargetStatuses($this->lastTransUnit[$this->markerPos]);
71 71
 
72 72
                         //prepare for an eventual next cycle
73 73
                         $this->markerPos++;
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
             // is outside current buffer (in the latter case, it's in next buffer to be read by the while loop);
95 95
             // this check is necessary because we may have truncated a tag in half with current read,
96 96
             // and the other half may be encountered in the next buffer it will be passed
97
-            if (isset($this->currentBuffer[ $idx - $this->offset ])) {
97
+            if (isset($this->currentBuffer[$idx - $this->offset])) {
98 98
                 // if this tag entire lenght fitted in the buffer, the last char must be the last
99 99
                 // symbol before the '>'; if it's an empty tag, it is assumed that it's a '/'
100 100
                 $tmp_offset = $idx - $this->offset;
101
-                $lastChar   = $this->currentBuffer[ $idx - $this->offset ];
101
+                $lastChar   = $this->currentBuffer[$idx - $this->offset];
102 102
             } else {
103 103
                 //if it's out, simple use the last character of the chunk
104 104
                 $tmp_offset = $this->len - 1;
105
-                $lastChar   = $this->currentBuffer[ $this->len - 1 ];
105
+                $lastChar   = $this->currentBuffer[$this->len - 1];
106 106
             }
107 107
 
108 108
             // trim last space
@@ -136,7 +136,7 @@  discard block
 block discarded – undo
136 136
                 } else {
137 137
                     //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
138 138
                     $this->bufferIsActive = true;
139
-                    $this->CDATABuffer    .= $tag;
139
+                    $this->CDATABuffer .= $tag;
140 140
                 }
141 141
             } else {
142 142
                 $this->postProcAndFlush($this->outputFP, $tag);
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
     {
157 157
         $endTags = "";
158 158
 
159
-        $segment     = Strings::removeDangerousChars($seg [ 'segment' ]);
160
-        $translation = Strings::removeDangerousChars($seg [ 'translation' ]);
159
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
160
+        $translation = Strings::removeDangerousChars($seg ['translation']);
161 161
         $dataRefMap  = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : [];
162 162
 
163
-        if (is_null($seg [ 'translation' ]) || $seg [ 'translation' ] == '') {
163
+        if (is_null($seg ['translation']) || $seg ['translation'] == '') {
164 164
             $translation = $segment;
165 165
         } else {
166 166
             if ($this->callback) {
@@ -173,20 +173,20 @@  discard block
 block discarded – undo
173 173
         // for Trados the trailing spaces after </mrk> are meaningful
174 174
         // so we trim the translation from Matecat DB and add them after </mrk>
175 175
         $trailingSpaces = '';
176
-        for ($s=0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++){
176
+        for ($s = 0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++) {
177 177
             $trailingSpaces .= ' ';
178 178
         }
179 179
 
180
-        if ($seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '') {
180
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
181 181
             if ($this->targetLang === 'ja-JP') {
182
-                $seg[ 'mrk_succ_tags' ] = ltrim($seg[ 'mrk_succ_tags' ]);
182
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
183 183
             }
184 184
 
185
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim($translation) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces;
185
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces;
186 186
         }
187 187
 
188 188
         // we need to trim succ_tags here because we already added the trailing spaces after </mrk>
189
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . ltrim($seg[ 'succ_tags' ]);
189
+        $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . ltrim($seg['succ_tags']);
190 190
 
191 191
         return $transUnitTranslation;
192 192
     }
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
             'REJECTED'   => 'RejectedTranslation',
207 207
         ];
208 208
 
209
-        return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" ";
209
+        return "conf=\"{$statusMap[$segment['status']]}\" ";
210 210
     }
211 211
 
212 212
     /**
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
      */
219 219
     protected function setTransUnitState($seg, $state_prop, $lastMrkState)
220 220
     {
221
-        return [ null, null ];
221
+        return [null, null];
222 222
     }
223 223
 
224 224
     /**
Please login to merge, or discard this patch.
src/XliffUtils/DataRefReplacer.php 1 patch
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
      *
18 18
      * @param array $map
19 19
      */
20
-    public function __construct( array $map)
20
+    public function __construct(array $map)
21 21
     {
22 22
         $this->map = $map;
23 23
     }
@@ -48,14 +48,14 @@  discard block
 block discarded – undo
48 48
         $html = HtmlParser::parse($string);
49 49
 
50 50
         // 1. Replace <ph>|<sc>|<ec> tags
51
-        foreach ($html as $node){
51
+        foreach ($html as $node) {
52 52
             $string = $this->recursiveAddEquivTextToPhTag($node, $string);
53 53
         }
54 54
 
55 55
         // 2. Replace <pc> tags
56 56
         $toBeEscaped = Strings::isAnEscapedHTML($string);
57 57
 
58
-        if($this->stringContainsPcTags($string, $toBeEscaped)){
58
+        if ($this->stringContainsPcTags($string, $toBeEscaped)) {
59 59
 
60 60
             // replace self-closed <pc />
61 61
             $string = $this->replaceSelfClosedPcTags($string, $toBeEscaped);
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
             'dataRefEnd',
85 85
         ];
86 86
 
87
-        foreach ($dataRefTags as $tag){
88
-            preg_match('/ '.$tag.'=[\\\\"](.*?)[\\\\"]/', $string, $matches);
87
+        foreach ($dataRefTags as $tag) {
88
+            preg_match('/ ' . $tag . '=[\\\\"](.*?)[\\\\"]/', $string, $matches);
89 89
 
90
-            if(count($matches) > 0){
90
+            if (count($matches) > 0) {
91 91
                 return true;
92 92
             }
93 93
         }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     {
103 103
         $html = HtmlParser::parse($string);
104 104
 
105
-        foreach ($html as $node){
105
+        foreach ($html as $node) {
106 106
             $string = $this->recursiveCleanFromEquivText($node, $string);
107 107
         }
108 108
 
@@ -122,10 +122,10 @@  discard block
 block discarded – undo
122 122
      *
123 123
      * @return string
124 124
      */
125
-    private function recursiveAddEquivTextToPhTag( $node, $string)
125
+    private function recursiveAddEquivTextToPhTag($node, $string)
126 126
     {
127
-        if($node->has_children){
128
-            foreach ($node->inner_html as $childNode){
127
+        if ($node->has_children) {
128
+            foreach ($node->inner_html as $childNode) {
129 129
                 $string = $this->recursiveAddEquivTextToPhTag($childNode, $string);
130 130
             }
131 131
         } else {
@@ -134,18 +134,18 @@  discard block
 block discarded – undo
134 134
                     return $string;
135 135
                 }
136 136
 
137
-                $a = $node->node;  // complete match. Eg:  <ph id="source1" dataRef="source1"/>
138
-                $b = $node->attributes['dataRef'];   // map identifier. Eg: source1
137
+                $a = $node->node; // complete match. Eg:  <ph id="source1" dataRef="source1"/>
138
+                $b = $node->attributes['dataRef']; // map identifier. Eg: source1
139 139
 
140 140
 
141 141
                 // if isset a value in the map calculate base64 encoded value
142 142
                 // otherwise skip
143
-                if(!in_array($b, array_keys($this->map))){
143
+                if (!in_array($b, array_keys($this->map))) {
144 144
                     return $string;
145 145
                 }
146 146
 
147 147
                 // check if is null, in this case convert it to NULL string
148
-                if(is_null($this->map[$b])){
148
+                if (is_null($this->map[$b])) {
149 149
                     $this->map[$b] = 'NULL';
150 150
                 }
151 151
 
@@ -157,19 +157,19 @@  discard block
 block discarded – undo
157 157
                 }
158 158
 
159 159
                 // if there is no id copy it from dataRef
160
-                $id = (!isset($node->attributes['id'])) ? ' id="'.$b.'" removeId="true"': '';
160
+                $id = (!isset($node->attributes['id'])) ? ' id="' . $b . '" removeId="true"' : '';
161 161
 
162 162
                 // introduce dataType for <ec>/<sc> tag handling
163
-                $dataType = ($this->isAEcOrScTag($node)) ? ' dataType="'.$node->tagname.'"' : '';
163
+                $dataType = ($this->isAEcOrScTag($node)) ? ' dataType="' . $node->tagname . '"' : '';
164 164
 
165 165
                 // replacement
166
-                $d = str_replace('/', $id.$dataType. ' equiv-text="base64:'.$base64EncodedValue.'"/', $a);
167
-                $a = str_replace(['<','>','&gt;', '&lt;'], '', $a);
168
-                $d = str_replace(['<','>','&gt;', '&lt;'], '', $d);
166
+                $d = str_replace('/', $id . $dataType . ' equiv-text="base64:' . $base64EncodedValue . '"/', $a);
167
+                $a = str_replace(['<', '>', '&gt;', '&lt;'], '', $a);
168
+                $d = str_replace(['<', '>', '&gt;', '&lt;'], '', $d);
169 169
 
170 170
                 // convert <ec>/<sc> into <ph>
171
-                if($this->isAEcOrScTag($node)){
172
-                    $d = 'ph'.substr($d, 2);
171
+                if ($this->isAEcOrScTag($node)) {
172
+                    $d = 'ph' . substr($d, 2);
173 173
                     $d = trim($d);
174 174
                 }
175 175
 
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
         $regex = ($toBeEscaped) ? '/&lt;pc (.*?)&gt;/iu' : '/<pc (.*?)>/iu';
192 192
         preg_match_all($regex, $string, $openingPcMatches);
193 193
 
194
-        return (isset($openingPcMatches[0]) && count($openingPcMatches[0])>0);
194
+        return (isset($openingPcMatches[0]) && count($openingPcMatches[0]) > 0);
195 195
     }
196 196
 
197 197
     /**
@@ -202,27 +202,27 @@  discard block
 block discarded – undo
202 202
      */
203 203
     private function replaceSelfClosedPcTags($string, $toBeEscaped)
204 204
     {
205
-        if($toBeEscaped){
206
-            $string = str_replace(['&lt;','&gt;'],['<','>'],$string);
205
+        if ($toBeEscaped) {
206
+            $string = str_replace(['&lt;', '&gt;'], ['<', '>'], $string);
207 207
         }
208 208
 
209 209
         $regex = '/<pc[^>]+?\/>/iu';
210 210
         preg_match_all($regex, $string, $selfClosedPcMatches);
211 211
 
212
-        foreach ($selfClosedPcMatches[0] as $match){
212
+        foreach ($selfClosedPcMatches[0] as $match) {
213 213
 
214 214
             $html = HtmlParser::parse($match);
215 215
             $node = $html[0];
216 216
             $attributes = $node->attributes;
217 217
 
218
-            if(isset($attributes['dataRefStart']) && array_key_exists($node->attributes['dataRefStart'], $this->map)){
219
-                $replacement = '<ph id="'.$attributes['id'].'" dataType="pcSelf" originalData="'.base64_encode($match).'" dataRef="'.$attributes['dataRefStart'].'" equiv-text="base64:'.base64_encode($this->map[$node->attributes['dataRefStart']]).'"/>';
218
+            if (isset($attributes['dataRefStart']) && array_key_exists($node->attributes['dataRefStart'], $this->map)) {
219
+                $replacement = '<ph id="' . $attributes['id'] . '" dataType="pcSelf" originalData="' . base64_encode($match) . '" dataRef="' . $attributes['dataRefStart'] . '" equiv-text="base64:' . base64_encode($this->map[$node->attributes['dataRefStart']]) . '"/>';
220 220
                 $string = str_replace($match, $replacement, $string);
221 221
             }
222 222
         }
223 223
 
224
-        if($toBeEscaped){
225
-            $string = str_replace(['<','>'],['&lt;','&gt;'],$string);
224
+        if ($toBeEscaped) {
225
+            $string = str_replace(['<', '>'], ['&lt;', '&gt;'], $string);
226 226
         }
227 227
 
228 228
         return $string;
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         $dataRefEndMap = [];
242 242
 
243 243
         foreach ($html as $index => $node) {
244
-            if ( $node->tagname === 'pc' ) {
244
+            if ($node->tagname === 'pc') {
245 245
                 $this->extractDataRefMapRecursively($node, $dataRefEndMap);
246 246
             }
247 247
         }
@@ -255,26 +255,26 @@  discard block
 block discarded – undo
255 255
      * @param object $node
256 256
      * @param $dataRefEndMap
257 257
      */
258
-    private function extractDataRefMapRecursively( $node, &$dataRefEndMap)
258
+    private function extractDataRefMapRecursively($node, &$dataRefEndMap)
259 259
     {
260
-        if($this->nodeContainsNestedPcTags($node)) {
261
-            foreach ( $node->inner_html as $nestedNode ) {
260
+        if ($this->nodeContainsNestedPcTags($node)) {
261
+            foreach ($node->inner_html as $nestedNode) {
262 262
                 $this->extractDataRefMapRecursively($nestedNode, $dataRefEndMap);
263 263
             }
264 264
         }
265 265
 
266 266
         // EXCLUDE self closed <pc/>
267
-        if($node->tagname === 'pc' && $node->self_closed === false){
268
-            if(isset($node->attributes['dataRefEnd'])){
267
+        if ($node->tagname === 'pc' && $node->self_closed === false) {
268
+            if (isset($node->attributes['dataRefEnd'])) {
269 269
                 $dataRefEnd = $node->attributes['dataRefEnd'];
270
-            } elseif(isset($node->attributes['dataRefStart'])) {
270
+            } elseif (isset($node->attributes['dataRefStart'])) {
271 271
                 $dataRefEnd = $node->attributes['dataRefStart'];
272 272
             } else {
273 273
                 $dataRefEnd = null;
274 274
             }
275 275
 
276 276
             $dataRefEndMap[] = [
277
-                    'id' => isset($node->attributes['id'] ) ? $node->attributes['id'] : null,
277
+                    'id' => isset($node->attributes['id']) ? $node->attributes['id'] : null,
278 278
                     'dataRefEnd' => $dataRefEnd,
279 279
             ];
280 280
         }
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
      */
289 289
     private function recursiveCleanFromEquivText($node, $string)
290 290
     {
291
-        if($node->has_children){
292
-            foreach ($node->inner_html as $childNode){
291
+        if ($node->has_children) {
292
+            foreach ($node->inner_html as $childNode) {
293 293
                 $string = $this->recursiveCleanFromEquivText($childNode, $string);
294 294
             }
295 295
         } else {
296
-            if(isset($node->attributes['dataRef']) && array_key_exists($node->attributes['dataRef'], $this->map)){
296
+            if (isset($node->attributes['dataRef']) && array_key_exists($node->attributes['dataRef'], $this->map)) {
297 297
                 $cleaned = preg_replace('/ equiv-text="(.*?)"/', '', $node->node);
298 298
                 $string = str_replace($node->node, $cleaned, $string);
299 299
             }
@@ -315,29 +315,29 @@  discard block
 block discarded – undo
315 315
         $regex = ($toBeEscaped) ? '/&lt;pc (.*?)&gt;/iu' : '/<pc (.*?)>/iu';
316 316
         preg_match_all($regex, $string, $openingPcMatches);
317 317
 
318
-        foreach ($openingPcMatches[0] as $index => $match){
318
+        foreach ($openingPcMatches[0] as $index => $match) {
319 319
             $attr = HtmlParser::getAttributes($openingPcMatches[1][$index]);
320 320
 
321 321
             // CASE 1 - Missing `dataRefStart`
322
-            if( isset($attr['dataRefEnd']) && !isset($attr['dataRefStart'])  ){
322
+            if (isset($attr['dataRefEnd']) && !isset($attr['dataRefStart'])) {
323 323
                 $attr['dataRefStart'] = $attr['dataRefEnd'];
324 324
             }
325 325
 
326 326
             // CASE 2 - Missing `dataRefEnd`
327
-            if( isset($attr['dataRefStart']) && !isset($attr['dataRefEnd'])  ){
327
+            if (isset($attr['dataRefStart']) && !isset($attr['dataRefEnd'])) {
328 328
                 $attr['dataRefEnd'] = $attr['dataRefStart'];
329 329
             }
330 330
 
331
-            if(isset($attr['dataRefStart'])){
331
+            if (isset($attr['dataRefStart'])) {
332 332
                 $startOriginalData = $match; // opening <pc>
333 333
                 $startValue = $this->map[$attr['dataRefStart']] ? $this->map[$attr['dataRefStart']] : 'NULL'; //handling null values in original data map
334 334
                 $base64EncodedStartValue = base64_encode($startValue);
335 335
                 $base64StartOriginalData = base64_encode($startOriginalData);
336 336
 
337 337
                 // conversion for opening <pc> tag
338
-                $openingPcConverted  = '<ph '. ((isset($attr['id'])) ? 'id="'.$attr['id'].'_1"' : '') .' dataType="pcStart" originalData="'.$base64StartOriginalData.'" dataRef="'
339
-                        .$attr['dataRefStart'].'" equiv-text="base64:'
340
-                        .$base64EncodedStartValue.'"/>';
338
+                $openingPcConverted = '<ph ' . ((isset($attr['id'])) ? 'id="' . $attr['id'] . '_1"' : '') . ' dataType="pcStart" originalData="' . $base64StartOriginalData . '" dataRef="'
339
+                        .$attr['dataRefStart'] . '" equiv-text="base64:'
340
+                        .$base64EncodedStartValue . '"/>';
341 341
 
342 342
                 $string = str_replace($startOriginalData, $openingPcConverted, $string);
343 343
             }
@@ -362,20 +362,20 @@  discard block
 block discarded – undo
362 362
         preg_match_all($regex, $string, $closingPcMatches, PREG_OFFSET_CAPTURE);
363 363
         $delta = 0;
364 364
 
365
-        foreach ( $closingPcMatches[ 0 ] as $index => $match ) {
365
+        foreach ($closingPcMatches[0] as $index => $match) {
366 366
             $offset = $match[1];
367 367
             $length = strlen($match[0]);
368 368
             $attr = $dataRefEndMap[$index];
369 369
 
370
-            if(!empty($attr) && isset($attr['dataRefEnd'])){
370
+            if (!empty($attr) && isset($attr['dataRefEnd'])) {
371 371
                 $endOriginalData = $match[0]; // </pc>
372 372
                 $endValue = $this->map[$attr['dataRefEnd']] ? $this->map[$attr['dataRefEnd']] : 'NULL';
373 373
                 $base64EncodedEndValue = base64_encode($endValue);
374 374
                 $base64EndOriginalData = base64_encode($endOriginalData);
375 375
 
376 376
                 // conversion for closing <pc> tag
377
-                $closingPcConverted = '<ph '. ((isset($attr['id'])) ? 'id="'.$attr['id'].'_2"': '') .' dataType="pcEnd" originalData="'.$base64EndOriginalData.'" dataRef="'
378
-                        .$attr['dataRefEnd'].'" equiv-text="base64:' .$base64EncodedEndValue.'"/>';
377
+                $closingPcConverted = '<ph ' . ((isset($attr['id'])) ? 'id="' . $attr['id'] . '_2"' : '') . ' dataType="pcEnd" originalData="' . $base64EndOriginalData . '" dataRef="'
378
+                        .$attr['dataRefEnd'] . '" equiv-text="base64:' . $base64EncodedEndValue . '"/>';
379 379
 
380 380
                 $realOffset = ($delta === 0) ? $offset : ($offset + $delta);
381 381
 
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
      */
395 395
     private function nodeContainsNestedPcTags($node)
396 396
     {
397
-        if(!$node->has_children){
397
+        if (!$node->has_children) {
398 398
             return false;
399 399
         }
400 400
 
401 401
         foreach ($node->inner_html as $nestedNode) {
402
-            if($nestedNode->tagname === 'pc' && (isset($node->attributes['dataRefEnd']) || isset($node->attributes['dataRefStart']))){
402
+            if ($nestedNode->tagname === 'pc' && (isset($node->attributes['dataRefEnd']) || isset($node->attributes['dataRefStart']))) {
403 403
                 return true;
404 404
             }
405 405
         }
@@ -423,7 +423,7 @@  discard block
 block discarded – undo
423 423
         $string = str_replace(' equiv-text=""', '', $string);
424 424
         $html = HtmlParser::parse($string);
425 425
 
426
-        foreach ($html as $node){
426
+        foreach ($html as $node) {
427 427
             $string = $this->recursiveRemoveOriginalData($node, $string);
428 428
         }
429 429
 
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
      */
439 439
     private function recursiveRemoveOriginalData($node, $string)
440 440
     {
441
-        if($node->has_children){
442
-            foreach ($node->inner_html as $childNode){
441
+        if ($node->has_children) {
442
+            foreach ($node->inner_html as $childNode) {
443 443
                 $string = $this->recursiveRemoveOriginalData($childNode, $string);
444 444
             }
445 445
         } else {
446 446
 
447
-            if(!isset($node->attributes['dataRef'])){
447
+            if (!isset($node->attributes['dataRef'])) {
448 448
                 return $string;
449 449
             }
450 450
 
451
-            $a = $node->node;                  // complete match. Eg:  <ph id="source1" dataRef="source1"/>
451
+            $a = $node->node; // complete match. Eg:  <ph id="source1" dataRef="source1"/>
452 452
             $b = $node->attributes['dataRef']; // map identifier. Eg: source1
453
-            $c = $node->terminator;            // terminator: Eg: >
453
+            $c = $node->terminator; // terminator: Eg: >
454 454
 
455 455
             // if isset a value in the map calculate base64 encoded value
456 456
             // or it is an empty string
457 457
             // otherwise skip
458
-            if(!in_array($b, array_keys($this->map))  ){
458
+            if (!in_array($b, array_keys($this->map))) {
459 459
                 return $string;
460 460
             }
461 461
 
462 462
             // check if is null, in this case convert it to NULL string
463
-            if(is_null($this->map[$b])){
463
+            if (is_null($this->map[$b])) {
464 464
                 $this->map[$b] = 'NULL';
465 465
             }
466 466
 
467 467
             // remove id?
468
-            $removeId = (isset($node->attributes['removeId']) && $node->attributes['removeId'] === "true") ? ' id="'.$b.'" removeId="true"' : '';
468
+            $removeId = (isset($node->attributes['removeId']) && $node->attributes['removeId'] === "true") ? ' id="' . $b . '" removeId="true"' : '';
469 469
 
470 470
             // grab dataType attribute for <ec>/<sc> tag handling
471
-            $dataType = ($this->wasAEcOrScTag($node)) ? ' dataType="'.$node->attributes['dataType'].'"' : '';
471
+            $dataType = ($this->wasAEcOrScTag($node)) ? ' dataType="' . $node->attributes['dataType'] . '"' : '';
472 472
 
473
-            $d = str_replace($removeId.$dataType.' equiv-text="base64:'.base64_encode($this->map[$b]).'"/'.$c, '/'.$c, $a);
473
+            $d = str_replace($removeId . $dataType . ' equiv-text="base64:' . base64_encode($this->map[$b]) . '"/' . $c, '/' . $c, $a);
474 474
 
475 475
             // replace original <ec>/<sc> tag
476
-            if($this->wasAEcOrScTag($node)){
477
-                $d = $node->attributes['dataType'].substr($d, 3);
476
+            if ($this->wasAEcOrScTag($node)) {
477
+                $d = $node->attributes['dataType'] . substr($d, 3);
478 478
                 $d = trim($d);
479 479
             }
480 480
 
@@ -487,7 +487,7 @@  discard block
 block discarded – undo
487 487
             $string = str_replace($a, $d, $string);
488 488
 
489 489
             // restoring <pc/> self-closed here
490
-            if(Strings::contains('dataType="pcSelf"', $d)){
490
+            if (Strings::contains('dataType="pcSelf"', $d)) {
491 491
                 preg_match('/\s?originalData="(.*?)"\s?/', $d, $originalDataMatches);
492 492
 
493 493
                 if (isset($originalDataMatches[1])) {
@@ -546,6 +546,6 @@  discard block
 block discarded – undo
546 546
      */
547 547
     private function wasAEcOrScTag($node)
548 548
     {
549
-        return (isset($node->attributes['dataType']) && ( $node->attributes['dataType'] === 'ec' || $node->attributes['dataType'] === 'sc'));
549
+        return (isset($node->attributes['dataType']) && ($node->attributes['dataType'] === 'ec' || $node->attributes['dataType'] === 'sc'));
550 550
     }
551 551
 }
Please login to merge, or discard this patch.