Passed
Push — master ( 9cdc2c...cd421c )
by Domenico
01:27 queued 17s
created
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.