Passed
Pull Request — master (#90)
by Domenico
08:32
created
src/XliffReplacer/XliffReplacerFactory.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -28,14 +28,14 @@
 block discarded – undo
28 28
             LoggerInterface                $logger = null,
29 29
             XliffReplacerCallbackInterface $callback = null
30 30
     ) {
31
-        $info = XliffProprietaryDetect::getInfo( $originalXliffPath );
31
+        $info = XliffProprietaryDetect::getInfo($originalXliffPath);
32 32
 
33
-        if ( $info[ 'version' ] == 1 && $info[ 'proprietary_short_name' ] !== 'trados' ) {
34
-            return new Xliff12( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
35
-        } elseif ( $info[ 'version' ] == 2 ) {
36
-            return new Xliff20( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
33
+        if ($info['version'] == 1 && $info['proprietary_short_name'] !== 'trados') {
34
+            return new Xliff12($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback);
35
+        } elseif ($info['version'] == 2) {
36
+            return new Xliff20($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback);
37 37
         }
38 38
 
39
-        return new XliffSdl( $originalXliffPath, $info[ 'version' ], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback );
39
+        return new XliffSdl($originalXliffPath, $info['version'], $data, $transUnits, $targetLang, $outputFilePath, $setSourceInTarget, $logger, $callback);
40 40
     }
41 41
 }
Please login to merge, or discard this patch.
src/XliffReplacer/Xliff12.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -27,14 +27,14 @@  discard block
 block discarded – undo
27 27
     /**
28 28
      * @inheritDoc
29 29
      */
30
-    protected function tagOpen( $parser, $name, $attr ) {
30
+    protected function tagOpen($parser, $name, $attr) {
31 31
 
32
-        $this->handleOpenUnit( $name, $attr );
32
+        $this->handleOpenUnit($name, $attr);
33 33
 
34 34
         // check if we are entering into a <target>
35
-        if ( 'target' === $name ) {
35
+        if ('target' === $name) {
36 36
 
37
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
37
+            if ($this->currentTransUnitIsTranslatable === 'no') {
38 38
                 $this->inTarget = false;
39 39
             } else {
40 40
                 $this->inTarget = true;
@@ -42,23 +42,23 @@  discard block
 block discarded – undo
42 42
         }
43 43
 
44 44
         // open buffer
45
-        if ( in_array( $name, $this->nodesToBuffer ) ) {
45
+        if (in_array($name, $this->nodesToBuffer)) {
46 46
             $this->bufferIsActive = true;
47 47
         }
48 48
 
49 49
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
50 50
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
51
-        if ( !$this->inTarget ) {
51
+        if (!$this->inTarget) {
52 52
 
53 53
             $tag = '';
54 54
 
55 55
             // construct tag
56 56
             $tag .= "<$name ";
57 57
 
58
-            foreach ( $attr as $k => $v ) {
58
+            foreach ($attr as $k => $v) {
59 59
 
60 60
                 //if tag name is file, we must replace the target-language attribute
61
-                if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) {
61
+                if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) {
62 62
                     //replace Target language with job language provided from constructor
63 63
                     $tag .= "$k=\"$this->targetLang\" ";
64 64
                 } else {
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
 
70 70
             $seg = $this->getCurrentSegment();
71 71
 
72
-            if ( $name === $this->tuTagName && !empty( $seg ) and isset( $seg[ 'sid' ] ) ) {
72
+            if ($name === $this->tuTagName && !empty($seg) and isset($seg['sid'])) {
73 73
 
74
-                if ( strpos( $tag, 'help-id' ) === false ) {
75
-                    if ( !empty( $seg[ 'sid' ] ) ) {
76
-                        $tag .= "help-id=\"{$seg[ 'sid' ]}\" ";
74
+                if (strpos($tag, 'help-id') === false) {
75
+                    if (!empty($seg['sid'])) {
76
+                        $tag .= "help-id=\"{$seg['sid']}\" ";
77 77
                     }
78 78
                 }
79 79
 
@@ -81,14 +81,14 @@  discard block
 block discarded – undo
81 81
 
82 82
             // Add MateCat specific namespace.
83 83
             // Add trgLang
84
-            if ( $name === 'xliff' ) {
85
-                if ( !array_key_exists( 'xmlns:mtc', $attr ) ) {
84
+            if ($name === 'xliff') {
85
+                if (!array_key_exists('xmlns:mtc', $attr)) {
86 86
                     $tag .= ' xmlns:mtc="https://www.matecat.com" ';
87 87
                 }
88
-                $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag );
88
+                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
89 89
             }
90 90
 
91
-            $this->checkForSelfClosedTagAndFlush( $parser, $tag );
91
+            $this->checkForSelfClosedTagAndFlush($parser, $tag);
92 92
 
93 93
         }
94 94
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
     /**
99 99
      * @inheritDoc
100 100
      */
101
-    protected function tagClose( $parser, $name ) {
101
+    protected function tagClose($parser, $name) {
102 102
         $tag = '';
103 103
 
104 104
         /**
@@ -107,15 +107,15 @@  discard block
 block discarded – undo
107 107
          *
108 108
          * self::tagOpen method
109 109
          */
110
-        if ( !$this->isEmpty ) {
110
+        if (!$this->isEmpty) {
111 111
 
112
-            if ( !$this->inTarget ) {
112
+            if (!$this->inTarget) {
113 113
                 $tag = "</$name>";
114 114
             }
115 115
 
116
-            if ( 'target' == $name ) {
116
+            if ('target' == $name) {
117 117
 
118
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
118
+                if (isset($this->transUnits[$this->currentTransUnitId])) {
119 119
 
120 120
                     // get translation of current segment, by indirect indexing: id -> positional index -> segment
121 121
                     // actually there may be more than one segment to that ID if there are two mrk of the same source segment
@@ -126,42 +126,42 @@  discard block
 block discarded – undo
126 126
                 $this->targetWasWritten = true;
127 127
                 // signal we are leaving a target
128 128
                 $this->inTarget = false;
129
-                $this->postProcAndFlush( $this->outputFP, $tag, true );
129
+                $this->postProcAndFlush($this->outputFP, $tag, true);
130 130
 
131
-            } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section
131
+            } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section
132 132
 
133 133
                 $this->bufferIsActive = false;
134 134
                 $tag                  = $this->CDATABuffer . "</$name>";
135 135
                 $this->CDATABuffer    = "";
136 136
 
137 137
                 //flush to the pointer
138
-                $this->postProcAndFlush( $this->outputFP, $tag );
138
+                $this->postProcAndFlush($this->outputFP, $tag);
139 139
 
140
-            } elseif ( $name === $this->tuTagName ) {
140
+            } elseif ($name === $this->tuTagName) {
141 141
 
142 142
                 $tag = "";
143 143
 
144 144
                 // handling </trans-unit> closure
145
-                if ( !$this->targetWasWritten ) {
145
+                if (!$this->targetWasWritten) {
146 146
 
147
-                    if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
147
+                    if (isset($this->transUnits[$this->currentTransUnitId])) {
148 148
                         $tag = $this->rebuildTarget();
149 149
                     } else {
150
-                        $tag = $this->createTargetTag( "", "" );
150
+                        $tag = $this->createTargetTag("", "");
151 151
                     }
152 152
 
153 153
                 }
154 154
 
155
-                $tag                    .= "</$this->tuTagName>";
155
+                $tag .= "</$this->tuTagName>";
156 156
                 $this->targetWasWritten = false;
157
-                $this->postProcAndFlush( $this->outputFP, $tag );
157
+                $this->postProcAndFlush($this->outputFP, $tag);
158 158
 
159
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
159
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
160 160
                 $this->CDATABuffer .= "</$name>";
161 161
                 // Do NOT Flush
162 162
             } else { //generic tag closure do Nothing
163 163
                 // flush to pointer
164
-                $this->postProcAndFlush( $this->outputFP, $tag );
164
+                $this->postProcAndFlush($this->outputFP, $tag);
165 165
             }
166 166
 
167 167
         } else {
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
         }
171 171
 
172 172
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
173
-        if ( $this->tuTagName === $name ) {
173
+        if ($this->tuTagName === $name) {
174 174
             $this->currentTransUnitIsTranslatable = null;
175 175
             $this->inTU                           = false;
176 176
             $this->hasWrittenCounts               = false;
@@ -187,35 +187,35 @@  discard block
 block discarded – undo
187 187
      *
188 188
      * @return string
189 189
      */
190
-    protected function prepareTranslation( array $seg, string $transUnitTranslation = "" ): string {
190
+    protected function prepareTranslation(array $seg, string $transUnitTranslation = ""): string {
191 191
 
192
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
193
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
192
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
193
+        $translation = Strings::removeDangerousChars($seg ['translation']);
194 194
 
195
-        if ( $seg [ 'translation' ] == '' ) {
195
+        if ($seg ['translation'] == '') {
196 196
             $translation = $segment;
197 197
         } else {
198
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
199
-                $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null;
200
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, [], $error ) ) {
198
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
199
+                $error = (!empty($seg['error'])) ? $seg['error'] : null;
200
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, [], $error)) {
201 201
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
202 202
                 }
203 203
             }
204 204
         }
205 205
 
206
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $this->rebuildMarks( $seg, $translation ) . ltrim( $seg[ 'succ_tags' ] );
206
+        $transUnitTranslation .= $seg['prev_tags'] . $this->rebuildMarks($seg, $translation) . ltrim($seg['succ_tags']);
207 207
 
208 208
         return $transUnitTranslation;
209 209
     }
210 210
 
211
-    protected function rebuildMarks( array $seg, string $translation ): string {
211
+    protected function rebuildMarks(array $seg, string $translation): string {
212 212
 
213
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
214
-            if ( $this->targetLang === 'ja-JP' ) {
215
-                $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] );
213
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
214
+            if ($this->targetLang === 'ja-JP') {
215
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
216 216
             }
217 217
 
218
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>";
218
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
219 219
         }
220 220
 
221 221
         return $translation;
@@ -230,10 +230,10 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return string
232 232
      */
233
-    private function createTargetTag( string $translation, string $stateProp ): string {
233
+    private function createTargetTag(string $translation, string $stateProp): string {
234 234
         $targetLang = ' xml:lang="' . $this->targetLang . '"';
235 235
         $tag        = "<target $targetLang $stateProp>$translation</target>";
236
-        $tag        .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts[ 'raw_word_count' ] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts[ 'eq_word_count' ] . '</count></count-group>';
236
+        $tag .= "\n<count-group name=\"$this->currentTransUnitId\"><count count-type=\"x-matecat-raw\">" . $this->counts['raw_word_count'] . "</count><count count-type=\"x-matecat-weighted\">" . $this->counts['eq_word_count'] . '</count></count-group>';
237 237
 
238 238
         return $tag;
239 239
 
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         // we must reset the lastMrkId found because this is a new segment.
250 250
         $lastMrkId = -1;
251 251
 
252
-        foreach ( $this->lastTransUnit as $pos => $seg ) {
252
+        foreach ($this->lastTransUnit as $pos => $seg) {
253 253
 
254 254
             /*
255 255
              * This routine works to respect the positional orders of markers.
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
              * pre-assign zero to the new mrk if this is the first one ( in this segment )
263 263
              * If it is null leave it NULL
264 264
              */
265
-            if ( (int)$seg[ "mrk_id" ] < 0 && $seg[ "mrk_id" ] !== null ) {
266
-                $seg[ "mrk_id" ] = 0;
265
+            if ((int)$seg["mrk_id"] < 0 && $seg["mrk_id"] !== null) {
266
+                $seg["mrk_id"] = 0;
267 267
             }
268 268
 
269 269
             /*
@@ -272,33 +272,33 @@  discard block
 block discarded – undo
272 272
              * ( null <= -1 ) === true
273 273
              * so, cast to int
274 274
              */
275
-            if ( (int)$seg[ "mrk_id" ] <= $lastMrkId ) {
275
+            if ((int)$seg["mrk_id"] <= $lastMrkId) {
276 276
                 break;
277 277
             }
278 278
 
279 279
             // update counts
280
-            if ( !empty( $seg ) ) {
281
-                $this->updateSegmentCounts( $seg );
280
+            if (!empty($seg)) {
281
+                $this->updateSegmentCounts($seg);
282 282
             }
283 283
 
284 284
             // delete translations so the prepareSegment
285 285
             // will put source content in target tag
286
-            if ( $this->sourceInTarget ) {
287
-                $seg[ 'translation' ] = '';
286
+            if ($this->sourceInTarget) {
287
+                $seg['translation'] = '';
288 288
                 $this->resetCounts();
289 289
             }
290 290
 
291 291
             // append $translation
292
-            $translation = $this->prepareTranslation( $seg, $translation );
292
+            $translation = $this->prepareTranslation($seg, $translation);
293 293
 
294
-            $lastMrkId = $seg[ "mrk_id" ];
294
+            $lastMrkId = $seg["mrk_id"];
295 295
 
296
-            [ $stateProp, $lastMrkState ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion, $stateProp, $lastMrkState );
296
+            [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion, $stateProp, $lastMrkState);
297 297
 
298 298
         }
299 299
 
300 300
         //append translation
301
-        return $this->createTargetTag( $translation, $stateProp );
301
+        return $this->createTargetTag($translation, $stateProp);
302 302
 
303 303
     }
304 304
 
Please login to merge, or discard this patch.
src/XliffReplacer/old__XliffSAXTranslationReplacer.php 1 patch
Spacing   +163 added lines, -163 removed lines patch added patch discarded remove patch
@@ -33,38 +33,38 @@  discard block
 block discarded – undo
33 33
     /**
34 34
      * @inheritDoc
35 35
      */
36
-    protected function tagOpen( $parser, $name, $attr ) {
36
+    protected function tagOpen($parser, $name, $attr) {
37 37
         // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
38
-        if ( $this->tuTagName === $name ) {
38
+        if ($this->tuTagName === $name) {
39 39
             $this->inTU = true;
40 40
 
41 41
             // get id
42 42
             // trim to first 100 characters because this is the limit on Matecat's DB
43
-            $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 );
43
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
44 44
 
45 45
             // `translate` attribute can be only yes or no
46
-            if ( isset( $attr[ 'translate' ] ) && $attr[ 'translate' ] === 'no' ) {
47
-                $attr[ 'translate' ] = 'no';
46
+            if (isset($attr['translate']) && $attr['translate'] === 'no') {
47
+                $attr['translate'] = 'no';
48 48
             } else {
49
-                $attr[ 'translate' ] = 'yes';
49
+                $attr['translate'] = 'yes';
50 50
             }
51 51
 
52 52
             // current 'translate' attribute of the current trans-unit
53
-            $this->currentTransUnitIsTranslatable = $attr[ 'translate' ];
53
+            $this->currentTransUnitIsTranslatable = $attr['translate'];
54 54
         }
55 55
 
56
-        if ( 'source' === $name ) {
56
+        if ('source' === $name) {
57 57
             $this->sourceAttributes = $attr;
58 58
         }
59 59
 
60
-        if ( 'mda:metadata' === $name ) {
60
+        if ('mda:metadata' === $name) {
61 61
             $this->unitContainsMda = true;
62 62
         }
63 63
 
64 64
         // check if we are entering into a <target>
65
-        if ( 'target' === $name ) {
65
+        if ('target' === $name) {
66 66
 
67
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
67
+            if ($this->currentTransUnitIsTranslatable === 'no') {
68 68
                 $this->inTarget = false;
69 69
             } else {
70 70
                 $this->inTarget = true;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 
74 74
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
75 75
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
76
-        if ( !$this->inTarget ) {
76
+        if (!$this->inTarget) {
77 77
 
78 78
             $tag = '';
79 79
 
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
             //
96 96
             // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit
97 97
             //
98
-            if ( $this->xliffVersion === 2 && ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) && $this->unitContainsMda === false ) {
99
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) && !empty( $this->transUnits[ $this->currentTransUnitId ] ) && !$this->hasWrittenCounts ) {
98
+            if ($this->xliffVersion === 2 && ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') && $this->unitContainsMda === false) {
99
+                if (isset($this->transUnits[$this->currentTransUnitId]) && !empty($this->transUnits[$this->currentTransUnitId]) && !$this->hasWrittenCounts) {
100 100
 
101 101
                     // we need to update counts here
102 102
                     $this->updateCounts();
@@ -112,40 +112,40 @@  discard block
 block discarded – undo
112 112
 
113 113
             $stateProp = null;
114 114
 
115
-            foreach ( $attr as $k => $v ) {
115
+            foreach ($attr as $k => $v) {
116 116
 
117 117
                 //if tag name is file, we must replace the target-language attribute
118
-                if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) {
118
+                if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) {
119 119
                     //replace Target language with job language provided from constructor
120 120
                     $tag .= "$k=\"$this->targetLang\" ";
121 121
                 } else {
122 122
                     $pos = 0;
123
-                    if ( $this->currentTransUnitId and isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
124
-                        $pos = current( $this->transUnits[ $this->currentTransUnitId ] );
123
+                    if ($this->currentTransUnitId and isset($this->transUnits[$this->currentTransUnitId])) {
124
+                        $pos = current($this->transUnits[$this->currentTransUnitId]);
125 125
                     }
126 126
 
127
-                    if ( $name === $this->tuTagName and isset( $this->segments[ $pos ] ) and isset( $this->segments[ $pos ][ 'sid' ] ) ) {
127
+                    if ($name === $this->tuTagName and isset($this->segments[$pos]) and isset($this->segments[$pos]['sid'])) {
128 128
 
129
-                        $sid = $this->segments[ $pos ][ 'sid' ];
129
+                        $sid = $this->segments[$pos]['sid'];
130 130
 
131 131
                         // add `help-id` to xliff v.1*
132 132
                         // add `mtc:segment-id` to xliff v.2*
133
-                        if ( $this->xliffVersion === 1 && strpos( $tag, 'help-id' ) === false ) {
134
-                            if ( !empty( $sid ) ) {
133
+                        if ($this->xliffVersion === 1 && strpos($tag, 'help-id') === false) {
134
+                            if (!empty($sid)) {
135 135
                                 $tag .= "help-id=\"$sid\" ";
136 136
                             }
137
-                        } elseif ( $this->xliffVersion === 2 && strpos( $tag, 'mtc:segment-id' ) === false ) {
138
-                            if ( !empty( $sid ) ) {
137
+                        } elseif ($this->xliffVersion === 2 && strpos($tag, 'mtc:segment-id') === false) {
138
+                            if (!empty($sid)) {
139 139
                                 $tag .= "mtc:segment-id=\"$sid\" ";
140 140
                             }
141 141
                         }
142 142
 
143
-                    } elseif ( 'segment' === $name && $this->xliffVersion === 2 ) { // add state to segment in Xliff v2
144
-                        [ $stateProp, ] = StatusToStateAttribute::getState( $this->segments[ $pos ][ 'status' ], $this->xliffVersion );
143
+                    } elseif ('segment' === $name && $this->xliffVersion === 2) { // add state to segment in Xliff v2
144
+                        [$stateProp, ] = StatusToStateAttribute::getState($this->segments[$pos]['status'], $this->xliffVersion);
145 145
                     }
146 146
 
147 147
                     //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute
148
-                    if ( $k != 'state' ) {
148
+                    if ($k != 'state') {
149 149
                         $tag .= "$k=\"$v\" ";
150 150
                     }
151 151
 
@@ -154,33 +154,33 @@  discard block
 block discarded – undo
154 154
             }
155 155
 
156 156
             // replace state for xliff v2
157
-            if ( $stateProp ) {
157
+            if ($stateProp) {
158 158
                 $tag .= $stateProp;
159 159
             }
160 160
 
161 161
             // add oasis xliff 20 namespace
162
-            if ( $this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) {
162
+            if ($this->xliffVersion === 2 && $name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) {
163 163
                 $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"';
164 164
             }
165 165
 
166 166
             // add MateCat specific namespace, we want maybe add non-XLIFF attributes
167
-            if ( $name === 'xliff' && !array_key_exists( 'xmlns:mtc', $attr ) ) {
167
+            if ($name === 'xliff' && !array_key_exists('xmlns:mtc', $attr)) {
168 168
                 $tag .= ' xmlns:mtc="https://www.matecat.com" ';
169 169
             }
170 170
 
171 171
             // trgLang
172
-            if ( $name === 'xliff' ) {
173
-                $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag );
172
+            if ($name === 'xliff') {
173
+                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
174 174
             }
175 175
 
176
-            $lastChar = $this->getLastCharacter( $parser );
176
+            $lastChar = $this->getLastCharacter($parser);
177 177
 
178 178
             //trim last space
179
-            $tag = rtrim( $tag );
179
+            $tag = rtrim($tag);
180 180
 
181 181
             //detect empty tag
182
-            $this->isEmpty = ( $lastChar == '/' || $name == 'x' );
183
-            if ( $this->isEmpty ) {
182
+            $this->isEmpty = ($lastChar == '/' || $name == 'x');
183
+            if ($this->isEmpty) {
184 184
                 $tag .= '/';
185 185
             }
186 186
 
@@ -188,29 +188,29 @@  discard block
 block discarded – undo
188 188
             $tag .= ">";
189 189
 
190 190
             //set a a Buffer for the segSource Source tag
191
-            if ( $this->bufferIsActive || in_array( $name, $this->nodesToCopy ) ) { // we are opening a critical CDATA section
191
+            if ($this->bufferIsActive || in_array($name, $this->nodesToCopy)) { // we are opening a critical CDATA section
192 192
 
193 193
                 //WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!!
194 194
                 //so check for isEmpty also in conjunction with name
195
-                if ( $this->isEmpty && ( 'source' === $name || 'seg-source' === $name ) ) {
196
-                    $this->postProcAndFlush( $this->outputFP, $tag );
195
+                if ($this->isEmpty && ('source' === $name || 'seg-source' === $name)) {
196
+                    $this->postProcAndFlush($this->outputFP, $tag);
197 197
                 } else {
198 198
                     //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
199 199
                     $this->bufferIsActive = true;
200
-                    $this->CDATABuffer    .= $tag;
200
+                    $this->CDATABuffer .= $tag;
201 201
                 }
202 202
             } else {
203
-                $this->postProcAndFlush( $this->outputFP, $tag );
203
+                $this->postProcAndFlush($this->outputFP, $tag);
204 204
             }
205 205
         }
206 206
 
207 207
         // update segmentPositionInTu
208 208
 
209
-        if ( $this->xliffVersion === 1 && $this->inTU && $name === 'source' ) {
209
+        if ($this->xliffVersion === 1 && $this->inTU && $name === 'source') {
210 210
             $this->segmentPositionInTu++;
211 211
         }
212 212
 
213
-        if ( $this->xliffVersion === 2 && $this->inTU && $name === 'segment' ) {
213
+        if ($this->xliffVersion === 2 && $this->inTU && $name === 'segment') {
214 214
             $this->segmentPositionInTu++;
215 215
         }
216 216
     }
@@ -218,7 +218,7 @@  discard block
 block discarded – undo
218 218
     /**
219 219
      * @inheritDoc
220 220
      */
221
-    protected function tagClose( $parser, $name ) {
221
+    protected function tagClose($parser, $name) {
222 222
         $tag = '';
223 223
 
224 224
         /**
@@ -227,26 +227,26 @@  discard block
 block discarded – undo
227 227
          *
228 228
          * self::tagOpen method
229 229
          */
230
-        if ( !$this->isEmpty ) {
230
+        if (!$this->isEmpty) {
231 231
 
232
-            if ( !$this->inTarget ) {
232
+            if (!$this->inTarget) {
233 233
                 $tag = "</$name>";
234 234
             }
235 235
 
236
-            if ( 'target' == $name ) {
236
+            if ('target' == $name) {
237 237
 
238
-                if ( $this->currentTransUnitIsTranslatable === 'no' ) {
238
+                if ($this->currentTransUnitIsTranslatable === 'no') {
239 239
                     // do nothing
240
-                } elseif ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
240
+                } elseif (isset($this->transUnits[$this->currentTransUnitId])) {
241 241
 
242 242
                     // get translation of current segment, by indirect indexing: id -> positional index -> segment
243 243
                     // actually there may be more that one segment to that ID if there are two mrk of the same source segment
244 244
 
245
-                    $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
245
+                    $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
246 246
 
247 247
                     // $currentSegmentId
248
-                    if ( !empty( $listOfSegmentsIds ) ) {
249
-                        $this->setCurrentSegmentArray( $listOfSegmentsIds );
248
+                    if (!empty($listOfSegmentsIds)) {
249
+                        $this->setCurrentSegmentArray($listOfSegmentsIds);
250 250
                     }
251 251
 
252 252
                     /*
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
                     $this->lastTransUnit = [];
264 264
 
265 265
                     $last_value    = null;
266
-                    $segmentsCount = count( $listOfSegmentsIds );
267
-                    for ( $i = 0; $i < $segmentsCount; $i++ ) {
268
-                        $id = $listOfSegmentsIds[ $i ];
269
-                        if ( isset( $this->segments[ $id ] ) && ( $i == 0 || $last_value + 1 == $listOfSegmentsIds[ $i ] ) ) {
270
-                            $last_value            = $listOfSegmentsIds[ $i ];
271
-                            $this->lastTransUnit[] = $this->segments[ $id ];
266
+                    $segmentsCount = count($listOfSegmentsIds);
267
+                    for ($i = 0; $i < $segmentsCount; $i++) {
268
+                        $id = $listOfSegmentsIds[$i];
269
+                        if (isset($this->segments[$id]) && ($i == 0 || $last_value + 1 == $listOfSegmentsIds[$i])) {
270
+                            $last_value            = $listOfSegmentsIds[$i];
271
+                            $this->lastTransUnit[] = $this->segments[$id];
272 272
                         }
273 273
                     }
274 274
 
@@ -280,28 +280,28 @@  discard block
 block discarded – undo
280 280
                     // we must reset the lastMrkId found because this is a new segment.
281 281
                     $lastMrkId = -1;
282 282
 
283
-                    if ( $this->xliffVersion === 2 ) {
284
-                        $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ];
283
+                    if ($this->xliffVersion === 2) {
284
+                        $seg = $this->segments[$this->currentSegmentArray['sid']];
285 285
 
286 286
                         // update counts
287
-                        if ( !$this->hasWrittenCounts && !empty( $seg ) ) {
288
-                            $this->updateSegmentCounts( $seg );
287
+                        if (!$this->hasWrittenCounts && !empty($seg)) {
288
+                            $this->updateSegmentCounts($seg);
289 289
                         }
290 290
 
291 291
                         // delete translations so the prepareSegment
292 292
                         // will put source content in target tag
293
-                        if ( $this->sourceInTarget ) {
294
-                            $seg[ 'translation' ] = '';
293
+                        if ($this->sourceInTarget) {
294
+                            $seg['translation'] = '';
295 295
                             $this->resetCounts();
296 296
                         }
297 297
 
298 298
                         // append $translation
299
-                        $translation = $this->prepareTranslation( $seg, $translation );
299
+                        $translation = $this->prepareTranslation($seg, $translation);
300 300
 
301
-                        [ $stateProp, ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion );
301
+                        [$stateProp, ] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion);
302 302
 
303 303
                     } else {
304
-                        foreach ( $listOfSegmentsIds as $pos => $id ) {
304
+                        foreach ($listOfSegmentsIds as $pos => $id) {
305 305
 
306 306
                             /*
307 307
                              * This routine works to respect the positional orders of markers.
@@ -314,8 +314,8 @@  discard block
 block discarded – undo
314 314
                              * pre-assign zero to the new mrk if this is the first one ( in this segment )
315 315
                              * If it is null leave it NULL
316 316
                              */
317
-                            if ( (int)$this->segments[ $id ][ "mrk_id" ] < 0 && $this->segments[ $id ][ "mrk_id" ] !== null ) {
318
-                                $this->segments[ $id ][ "mrk_id" ] = 0;
317
+                            if ((int)$this->segments[$id]["mrk_id"] < 0 && $this->segments[$id]["mrk_id"] !== null) {
318
+                                $this->segments[$id]["mrk_id"] = 0;
319 319
                             }
320 320
 
321 321
                             /*
@@ -324,62 +324,62 @@  discard block
 block discarded – undo
324 324
                              * ( null <= -1 ) === true
325 325
                              * so, cast to int
326 326
                              */
327
-                            if ( (int)$this->segments[ $id ][ "mrk_id" ] <= $lastMrkId ) {
327
+                            if ((int)$this->segments[$id]["mrk_id"] <= $lastMrkId) {
328 328
                                 break;
329 329
                             }
330 330
 
331 331
                             // set $this->currentSegment
332
-                            $seg = $this->segments[ $id ];
332
+                            $seg = $this->segments[$id];
333 333
 
334 334
                             // update counts
335
-                            if ( !empty( $seg ) ) {
336
-                                $this->updateSegmentCounts( $seg );
335
+                            if (!empty($seg)) {
336
+                                $this->updateSegmentCounts($seg);
337 337
                             }
338 338
 
339 339
                             // delete translations so the prepareSegment
340 340
                             // will put source content in target tag
341
-                            if ( $this->sourceInTarget ) {
342
-                                $seg[ 'translation' ] = '';
341
+                            if ($this->sourceInTarget) {
342
+                                $seg['translation'] = '';
343 343
                                 $this->resetCounts();
344 344
                             }
345 345
 
346 346
                             // append $translation
347
-                            $translation = $this->prepareTranslation( $seg, $translation );
347
+                            $translation = $this->prepareTranslation($seg, $translation);
348 348
 
349 349
                             // for xliff 2 we need $this->transUnits[ $this->currentId ] [ $pos ] for populating metadata
350 350
 
351
-                            unset( $this->transUnits[ $this->currentTransUnitId ] [ $pos ] );
351
+                            unset($this->transUnits[$this->currentTransUnitId] [$pos]);
352 352
 
353
-                            $lastMrkId = $this->segments[ $id ][ "mrk_id" ];
353
+                            $lastMrkId = $this->segments[$id]["mrk_id"];
354 354
 
355
-                            [ $stateProp, $lastMrkState ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion, $stateProp, $lastMrkState );
355
+                            [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion, $stateProp, $lastMrkState);
356 356
 
357 357
                         }
358 358
                     }
359 359
 
360 360
                     //append translation
361
-                    $tag = $this->createTargetTag( $translation, $stateProp );
361
+                    $tag = $this->createTargetTag($translation, $stateProp);
362 362
 
363 363
                 }
364 364
 
365 365
                 // signal we are leaving a target
366 366
                 $this->targetWasWritten = true;
367 367
                 $this->inTarget         = false;
368
-                $this->postProcAndFlush( $this->outputFP, $tag, true );
369
-            } elseif ( in_array( $name, $this->nodesToCopy ) && !$this->inTarget ) { // we are closing a critical CDATA section
368
+                $this->postProcAndFlush($this->outputFP, $tag, true);
369
+            } elseif (in_array($name, $this->nodesToCopy) && !$this->inTarget) { // we are closing a critical CDATA section
370 370
 
371 371
                 $this->bufferIsActive = false;
372 372
 
373 373
                 // only for Xliff 2.*
374 374
                 // write here <mda:metaGroup> and <mda:meta> if already present in the <unit>
375
-                if ( 'mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts ) {
375
+                if ('mda:metadata' === $name && $this->unitContainsMda && $this->xliffVersion === 2 && !$this->hasWrittenCounts) {
376 376
 
377 377
                     // we need to update counts here
378 378
                     $this->updateCounts();
379 379
                     $this->hasWrittenCounts = true;
380 380
 
381 381
                     $tag = $this->CDATABuffer;
382
-                    $tag .= $this->getWordCountGroupForXliffV2( false );
382
+                    $tag .= $this->getWordCountGroupForXliffV2(false);
383 383
                     $tag .= "    </mda:metadata>";
384 384
 
385 385
                 } else {
@@ -389,22 +389,22 @@  discard block
 block discarded – undo
389 389
                 $this->CDATABuffer = "";
390 390
 
391 391
                 //flush to pointer
392
-                $this->postProcAndFlush( $this->outputFP, $tag );
393
-            } elseif ( 'segment' === $name ) {
392
+                $this->postProcAndFlush($this->outputFP, $tag);
393
+            } elseif ('segment' === $name) {
394 394
 
395 395
                 // only for Xliff 2.*
396 396
                 // if segment has no <target> add it BEFORE </segment>
397
-                if ( !$this->targetWasWritten ) {
397
+                if (!$this->targetWasWritten) {
398 398
 
399 399
                     $seg = $this->getCurrentSegment();
400 400
 
401
-                    if ( isset( $seg[ 'translation' ] ) ) {
401
+                    if (isset($seg['translation'])) {
402 402
 
403
-                        $translation = $this->prepareTranslation( $seg );
404
-                        [ $stateProp, ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion );
403
+                        $translation = $this->prepareTranslation($seg);
404
+                        [$stateProp, ] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion);
405 405
 
406 406
                         // replace the tag
407
-                        $tag = $this->createTargetTag( $translation, $stateProp );
407
+                        $tag = $this->createTargetTag($translation, $stateProp);
408 408
 
409 409
                         $tag .= '</segment>';
410 410
 
@@ -412,46 +412,46 @@  discard block
 block discarded – undo
412 412
 
413 413
                 }
414 414
 
415
-                $this->postProcAndFlush( $this->outputFP, $tag );
415
+                $this->postProcAndFlush($this->outputFP, $tag);
416 416
 
417 417
                 // we are leaving <segment>, reset $segmentHasTarget
418 418
                 $this->targetWasWritten = false;
419 419
 
420
-            } elseif ( $name === 'trans-unit' ) {
420
+            } elseif ($name === 'trans-unit') {
421 421
 
422 422
                 // only for Xliff 1.*
423 423
                 // handling </trans-unit> closure
424
-                if ( !$this->targetWasWritten ) {
424
+                if (!$this->targetWasWritten) {
425 425
 
426 426
                     $seg = $this->getCurrentSegment();
427 427
 
428
-                    if ( isset( $seg[ 'translation' ] ) ) {
429
-                        $translation = $this->prepareTranslation( $seg );
430
-                        [ $stateProp, ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion );
428
+                    if (isset($seg['translation'])) {
429
+                        $translation = $this->prepareTranslation($seg);
430
+                        [$stateProp, ] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion);
431 431
 
432 432
                         // replace the tag
433
-                        $tag = $this->createTargetTag( $translation, $stateProp );
433
+                        $tag = $this->createTargetTag($translation, $stateProp);
434 434
                         $tag .= '</trans-unit>';
435 435
 
436 436
                     }
437 437
 
438
-                    $this->postProcAndFlush( $this->outputFP, $tag );
438
+                    $this->postProcAndFlush($this->outputFP, $tag);
439 439
 
440 440
                 } else {
441
-                    $this->postProcAndFlush( $this->outputFP, '</trans-unit>' );
441
+                    $this->postProcAndFlush($this->outputFP, '</trans-unit>');
442 442
                     $this->targetWasWritten = false;
443 443
                 }
444 444
 
445 445
 
446
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
446
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
447 447
                 $this->CDATABuffer .= "</$name>";
448 448
                 // Do NOT Flush
449 449
             } else { //generic tag closure do Nothing
450 450
                 // flush to pointer
451
-                $this->postProcAndFlush( $this->outputFP, $tag );
451
+                $this->postProcAndFlush($this->outputFP, $tag);
452 452
             }
453
-        } elseif ( $this->CDATABuffer === '<note/>' && $this->bufferIsActive === true ) {
454
-            $this->postProcAndFlush( $this->outputFP, '<note/>' );
453
+        } elseif ($this->CDATABuffer === '<note/>' && $this->bufferIsActive === true) {
454
+            $this->postProcAndFlush($this->outputFP, '<note/>');
455 455
             $this->bufferIsActive = false;
456 456
             $this->CDATABuffer    = '';
457 457
             $this->isEmpty        = false;
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
         }
462 462
 
463 463
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
464
-        if ( $this->tuTagName === $name ) {
464
+        if ($this->tuTagName === $name) {
465 465
             $this->currentTransUnitIsTranslatable = null;
466 466
             $this->inTU                           = false;
467 467
             $this->segmentPositionInTu       = -1;
@@ -478,20 +478,20 @@  discard block
 block discarded – undo
478 478
      *
479 479
      * @param array $listOfSegmentsIds
480 480
      */
481
-    private function setCurrentSegmentArray( array $listOfSegmentsIds = [] ) {
481
+    private function setCurrentSegmentArray(array $listOfSegmentsIds = []) {
482 482
         // $currentSegmentId
483
-        if ( empty( $this->currentSegmentArray ) ) {
483
+        if (empty($this->currentSegmentArray)) {
484 484
             $this->currentSegmentArray = [
485
-                    'sid' => $listOfSegmentsIds[ 0 ],
485
+                    'sid' => $listOfSegmentsIds[0],
486 486
                     'tid' => $this->currentTransUnitId,
487 487
             ];
488 488
         } else {
489
-            if ( $this->currentSegmentArray[ 'tid' ] === $this->currentTransUnitId ) {
490
-                $key                                = array_search( $this->currentSegmentArray[ 'sid' ], $listOfSegmentsIds );
491
-                $this->currentSegmentArray[ 'sid' ] = $listOfSegmentsIds[ $key + 1 ];
489
+            if ($this->currentSegmentArray['tid'] === $this->currentTransUnitId) {
490
+                $key                                = array_search($this->currentSegmentArray['sid'], $listOfSegmentsIds);
491
+                $this->currentSegmentArray['sid'] = $listOfSegmentsIds[$key + 1];
492 492
             } else {
493 493
                 $this->currentSegmentArray = [
494
-                        'sid' => $listOfSegmentsIds[ 0 ],
494
+                        'sid' => $listOfSegmentsIds[0],
495 495
                         'tid' => $this->currentTransUnitId,
496 496
                 ];
497 497
             }
@@ -503,23 +503,23 @@  discard block
 block discarded – undo
503 503
      */
504 504
     private function updateCounts() {
505 505
         // populate counts
506
-        $listOfSegmentsIds = $this->transUnits[ $this->currentTransUnitId ];
506
+        $listOfSegmentsIds = $this->transUnits[$this->currentTransUnitId];
507 507
 
508 508
         // $currentSegmentId
509
-        if ( !empty( $listOfSegmentsIds ) ) {
510
-            $this->setCurrentSegmentArray( $listOfSegmentsIds );
509
+        if (!empty($listOfSegmentsIds)) {
510
+            $this->setCurrentSegmentArray($listOfSegmentsIds);
511 511
         }
512 512
 
513
-        if ( $this->xliffVersion === 2 ) {
514
-            $seg = $this->segments[ $this->currentSegmentArray[ 'sid' ] ];
515
-            if ( !empty( $seg ) ) {
516
-                $this->updateSegmentCounts( $seg );
513
+        if ($this->xliffVersion === 2) {
514
+            $seg = $this->segments[$this->currentSegmentArray['sid']];
515
+            if (!empty($seg)) {
516
+                $this->updateSegmentCounts($seg);
517 517
             }
518 518
         } else {
519
-            foreach ( $listOfSegmentsIds as $pos => $id ) {
520
-                $seg = $this->segments[ $id ];
521
-                if ( !empty( $seg ) ) {
522
-                    $this->updateSegmentCounts( $seg );
519
+            foreach ($listOfSegmentsIds as $pos => $id) {
520
+                $seg = $this->segments[$id];
521
+                if (!empty($seg)) {
522
+                    $this->updateSegmentCounts($seg);
523 523
                 }
524 524
             }
525 525
         }
@@ -530,24 +530,24 @@  discard block
 block discarded – undo
530 530
     /**
531 531
      * @param array $seg
532 532
      */
533
-    private function updateSegmentCounts( array $seg = [] ) {
533
+    private function updateSegmentCounts(array $seg = []) {
534 534
 
535
-        $raw_word_count = $seg[ 'raw_word_count' ];
536
-        $eq_word_count  = ( floor( $seg[ 'eq_word_count' ] * 100 ) / 100 );
535
+        $raw_word_count = $seg['raw_word_count'];
536
+        $eq_word_count  = (floor($seg['eq_word_count'] * 100) / 100);
537 537
 
538
-        $this->counts[ 'segments_count_array' ][ $seg[ 'sid' ] ] = [
538
+        $this->counts['segments_count_array'][$seg['sid']] = [
539 539
                 'raw_word_count' => $raw_word_count,
540 540
                 'eq_word_count'  => $eq_word_count,
541 541
         ];
542 542
 
543
-        $this->counts[ 'raw_word_count' ] += $raw_word_count;
544
-        $this->counts[ 'eq_word_count' ]  += $eq_word_count;
543
+        $this->counts['raw_word_count'] += $raw_word_count;
544
+        $this->counts['eq_word_count']  += $eq_word_count;
545 545
     }
546 546
 
547 547
     private function resetCounts() {
548
-        $this->counts[ 'segments_count_array' ] = [];
549
-        $this->counts[ 'raw_word_count' ]       = 0;
550
-        $this->counts[ 'eq_word_count' ]        = 0;
548
+        $this->counts['segments_count_array'] = [];
549
+        $this->counts['raw_word_count']       = 0;
550
+        $this->counts['eq_word_count']        = 0;
551 551
     }
552 552
 
553 553
     /**
@@ -558,38 +558,38 @@  discard block
 block discarded – undo
558 558
      *
559 559
      * @return string
560 560
      */
561
-    protected function prepareTranslation( $seg, $transUnitTranslation = "" ) {
561
+    protected function prepareTranslation($seg, $transUnitTranslation = "") {
562 562
         $endTags = "";
563 563
 
564
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
565
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
566
-        $dataRefMap  = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : [];
564
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
565
+        $translation = Strings::removeDangerousChars($seg ['translation']);
566
+        $dataRefMap  = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : [];
567 567
 
568
-        if ( $seg [ 'translation' ] == '' ) {
568
+        if ($seg ['translation'] == '') {
569 569
             $translation = $segment;
570 570
         } else {
571
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
572
-                $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null;
573
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) {
571
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
572
+                $error = (!empty($seg['error'])) ? $seg['error'] : null;
573
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) {
574 574
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
575 575
                 }
576 576
             }
577 577
         }
578 578
 
579 579
         // for xliff v2 we ignore the marks on purpose
580
-        if ( $this->xliffVersion === 2 ) {
580
+        if ($this->xliffVersion === 2) {
581 581
             return $translation;
582 582
         }
583 583
 
584
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
585
-            if ( $this->targetLang === 'ja-JP' ) {
586
-                $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] );
584
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
585
+            if ($this->targetLang === 'ja-JP') {
586
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
587 587
             }
588 588
 
589
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>";
589
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
590 590
         }
591 591
 
592
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . $seg[ 'succ_tags' ];
592
+        $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . $seg['succ_tags'];
593 593
 
594 594
         return $transUnitTranslation;
595 595
     }
@@ -601,7 +601,7 @@  discard block
 block discarded – undo
601 601
      *
602 602
      * @return string
603 603
      */
604
-    private function getWordCountGroup( $raw_word_count, $eq_word_count ) {
604
+    private function getWordCountGroup($raw_word_count, $eq_word_count) {
605 605
         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>";
606 606
     }
607 607
 
@@ -609,11 +609,11 @@  discard block
 block discarded – undo
609 609
      * @return array
610 610
      */
611 611
     private function getCurrentSegment() {
612
-        if ( $this->currentTransUnitIsTranslatable === 'yes' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
613
-            $index = $this->transUnits[ $this->currentTransUnitId ][ $this->segmentPositionInTu ];
612
+        if ($this->currentTransUnitIsTranslatable === 'yes' && isset($this->transUnits[$this->currentTransUnitId])) {
613
+            $index = $this->transUnits[$this->currentTransUnitId][$this->segmentPositionInTu];
614 614
 
615
-            if ( isset( $this->segments[ $index ] ) ) {
616
-                return $this->segments[ $index ];
615
+            if (isset($this->segments[$index])) {
616
+                return $this->segments[$index];
617 617
             }
618 618
         }
619 619
 
@@ -628,21 +628,21 @@  discard block
 block discarded – undo
628 628
      *
629 629
      * @return string
630 630
      */
631
-    private function createTargetTag( $translation, $stateProp ) {
631
+    private function createTargetTag($translation, $stateProp) {
632 632
 
633 633
         $targetLang = '';
634
-        if ( $this->xliffVersion === 1 ) {
634
+        if ($this->xliffVersion === 1) {
635 635
             $targetLang = ' xml:lang="' . $this->targetLang . '"';
636 636
         }
637 637
 
638
-        switch ( $this->xliffVersion ) {
638
+        switch ($this->xliffVersion) {
639 639
             case 1:
640 640
             default:
641 641
                 $tag = "<target $targetLang $stateProp>$translation</target>";
642 642
 
643 643
                 // if it's a Trados file don't append count group
644
-                if ( get_class( $this ) !== oldSdlOldXliffSAXTranslationReplacer::class ) {
645
-                    $tag .= $this->getWordCountGroup( $this->counts[ 'raw_word_count' ], $this->counts[ 'eq_word_count' ] );
644
+                if (get_class($this) !== oldSdlOldXliffSAXTranslationReplacer::class) {
645
+                    $tag .= $this->getWordCountGroup($this->counts['raw_word_count'], $this->counts['eq_word_count']);
646 646
                 }
647 647
 
648 648
                 return $tag;
@@ -658,33 +658,33 @@  discard block
 block discarded – undo
658 658
      *
659 659
      * @return string
660 660
      */
661
-    private function getWordCountGroupForXliffV2( $withMetadataTag = true ) {
661
+    private function getWordCountGroupForXliffV2($withMetadataTag = true) {
662 662
 
663 663
         $this->mdaGroupCounter++;
664
-        $segments_count_array = $this->counts[ 'segments_count_array' ];
664
+        $segments_count_array = $this->counts['segments_count_array'];
665 665
 
666 666
         $id = $this->currentSegmentArray;
667 667
 
668 668
 
669 669
         $return = '';
670 670
 
671
-        if ( $withMetadataTag === true ) {
671
+        if ($withMetadataTag === true) {
672 672
             $return .= '<mda:metadata>';
673 673
         }
674 674
 
675 675
         $index = 0;
676
-        foreach ( $segments_count_array as $segments_count_item ) {
676
+        foreach ($segments_count_array as $segments_count_item) {
677 677
 
678 678
             $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']';
679 679
             $index++;
680 680
 
681 681
             $return .= "    <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\">
682
-                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta>
683
-                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta>
682
+                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta>
683
+                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta>
684 684
                             </mda:metaGroup>";
685 685
         }
686 686
 
687
-        if ( $withMetadataTag === true ) {
687
+        if ($withMetadataTag === true) {
688 688
             $return .= '</mda:metadata>';
689 689
         }
690 690
 
Please login to merge, or discard this patch.
src/XliffReplacer/StatusToStateAttribute.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -22,26 +22,26 @@  discard block
 block discarded – undo
22 22
      *
23 23
      * @return array
24 24
      */
25
-    public static function getState( string $status, int $xliffVersion, ?string $state_prop = '', ?string $lastMrkState = '' ): array {
25
+    public static function getState(string $status, int $xliffVersion, ?string $state_prop = '', ?string $lastMrkState = ''): array {
26 26
 
27
-        switch ( $status ) {
27
+        switch ($status) {
28 28
 
29 29
             case TranslationStatus::STATUS_FIXED:
30 30
             case TranslationStatus::STATUS_APPROVED2:
31
-                if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2 ) {
31
+                if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED2) {
32 32
                     $state_prop   = "state=\"final\"";
33 33
                     $lastMrkState = TranslationStatus::STATUS_APPROVED2;
34 34
                 }
35 35
                 break;
36 36
             case TranslationStatus::STATUS_APPROVED:
37
-                if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED ) {
38
-                    $state_prop   = ( $xliffVersion === 2 ) ? "state=\"reviewed\"" : "state=\"signed-off\"";
37
+                if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_APPROVED) {
38
+                    $state_prop   = ($xliffVersion === 2) ? "state=\"reviewed\"" : "state=\"signed-off\"";
39 39
                     $lastMrkState = TranslationStatus::STATUS_APPROVED;
40 40
                 }
41 41
                 break;
42 42
 
43 43
             case TranslationStatus::STATUS_TRANSLATED:
44
-                if ( $lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED ) {
44
+                if ($lastMrkState == null || $lastMrkState == TranslationStatus::STATUS_TRANSLATED || $lastMrkState == TranslationStatus::STATUS_APPROVED) {
45 45
                     $state_prop   = "state=\"translated\"";
46 46
                     $lastMrkState = TranslationStatus::STATUS_TRANSLATED;
47 47
                 }
@@ -49,22 +49,22 @@  discard block
 block discarded – undo
49 49
 
50 50
             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
51 51
             case TranslationStatus::STATUS_REBUTTED:
52
-                if ( ( $lastMrkState == null ) || ( $lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT ) ) {
53
-                    $state_prop   = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"needs-review-translation\"";
52
+                if (($lastMrkState == null) || ($lastMrkState != TranslationStatus::STATUS_NEW || $lastMrkState != TranslationStatus::STATUS_DRAFT)) {
53
+                    $state_prop   = ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"needs-review-translation\"";
54 54
                     $lastMrkState = TranslationStatus::STATUS_REJECTED;
55 55
                 }
56 56
                 break;
57 57
 
58 58
             case TranslationStatus::STATUS_NEW:
59
-                if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_NEW ) {
60
-                    $state_prop   = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"";
59
+                if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_NEW) {
60
+                    $state_prop   = ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"";
61 61
                     $lastMrkState = TranslationStatus::STATUS_NEW;
62 62
                 }
63 63
                 break;
64 64
 
65 65
             case TranslationStatus::STATUS_DRAFT:
66
-                if ( ( $lastMrkState == null ) || $lastMrkState != TranslationStatus::STATUS_DRAFT ) {
67
-                    $state_prop   = ( $xliffVersion === 2 ) ? "state=\"initial\"" : "state=\"new\"";
66
+                if (($lastMrkState == null) || $lastMrkState != TranslationStatus::STATUS_DRAFT) {
67
+                    $state_prop   = ($xliffVersion === 2) ? "state=\"initial\"" : "state=\"new\"";
68 68
                     $lastMrkState = TranslationStatus::STATUS_DRAFT;
69 69
                 }
70 70
                 break;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                 // this is the case when a segment is not showed in cattool, so the row in
74 74
                 // segment_translations does not exists and
75 75
                 // ---> $seg[ 'status' ] is NULL
76
-                if ( $lastMrkState == null ) { //this is the first MRK ID
76
+                if ($lastMrkState == null) { //this is the first MRK ID
77 77
                     $state_prop   = "state=\"translated\"";
78 78
                     $lastMrkState = TranslationStatus::STATUS_TRANSLATED;
79 79
                 } else {
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 break;
83 83
         }
84 84
 
85
-        return [ $state_prop, $lastMrkState ];
85
+        return [$state_prop, $lastMrkState];
86 86
 
87 87
     }
88 88
 
Please login to merge, or discard this patch.
src/XliffReplacer/old__SdlXliffSAXTranslationReplacer.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -10,22 +10,22 @@  discard block
 block discarded – undo
10 10
     /**
11 11
      * @inheritDoc
12 12
      */
13
-    protected function tagOpen( $parser, $name, $attr ) {
13
+    protected function tagOpen($parser, $name, $attr) {
14 14
         // check if we are entering into a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
15
-        if ( $this->tuTagName === $name ) {
15
+        if ($this->tuTagName === $name) {
16 16
             $this->inTU = true;
17 17
 
18 18
             // get id
19 19
             // trim to first 100 characters because this is the limit on Matecat's DB
20
-            $this->currentTransUnitId = substr( $attr[ 'id' ], 0, 100 );
20
+            $this->currentTransUnitId = substr($attr['id'], 0, 100);
21 21
 
22 22
             // current 'translate' attribute of the current trans-unit
23
-            $this->currentTransUnitIsTranslatable = isset( $attr[ 'translate' ] ) ? $attr[ 'translate' ] : 'yes';
23
+            $this->currentTransUnitIsTranslatable = isset($attr['translate']) ? $attr['translate'] : 'yes';
24 24
         }
25 25
 
26 26
         // check if we are entering into a <target>
27
-        if ( 'target' == $name ) {
28
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
27
+        if ('target' == $name) {
28
+            if ($this->currentTransUnitIsTranslatable === 'no') {
29 29
                 $this->inTarget = false;
30 30
             } else {
31 31
                 $this->inTarget = true;
@@ -33,13 +33,13 @@  discard block
 block discarded – undo
33 33
         }
34 34
 
35 35
         // reset Marker positions
36
-        if ( 'sdl:seg-defs' == $name ) {
36
+        if ('sdl:seg-defs' == $name) {
37 37
             $this->segmentInUnitPosition = 0;
38 38
         }
39 39
 
40 40
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
41 41
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
42
-        if ( !$this->inTarget ) {
42
+        if (!$this->inTarget) {
43 43
 
44 44
             // costruct tag
45 45
             $tag = "<$name ";
@@ -49,23 +49,23 @@  discard block
 block discarded – undo
49 49
             // so the check on it's name is not enough
50 50
             $_sdlStatus_confWritten = false;
51 51
 
52
-            foreach ( $attr as $k => $v ) {
52
+            foreach ($attr as $k => $v) {
53 53
 
54 54
                 // if tag name is file, we must replace the target-language attribute
55
-                if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) {
55
+                if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) {
56 56
                     //replace Target language with job language provided from constructor
57 57
                     $tag .= "$k=\"$this->targetLang\" ";
58 58
 
59
-                    if ( null !== $this->logger ) {
60
-                        $this->logger->debug( $k . " => " . $this->targetLang );
59
+                    if (null !== $this->logger) {
60
+                        $this->logger->debug($k . " => " . $this->targetLang);
61 61
                     }
62
-                } elseif ( 'sdl:seg' == $name ) {
62
+                } elseif ('sdl:seg' == $name) {
63 63
 
64 64
                     // write the confidence level for this segment ( Translated, Draft, etc. )
65
-                    if ( isset( $this->segments[ 'matecat|' . $this->currentTransUnitId ] ) && $_sdlStatus_confWritten === false ) {
65
+                    if (isset($this->segments['matecat|' . $this->currentTransUnitId]) && $_sdlStatus_confWritten === false) {
66 66
 
67 67
                         // append definition attribute
68
-                        $tag .= $this->prepareTargetStatuses( $this->lastTransUnit[ $this->segmentInUnitPosition ] );
68
+                        $tag .= $this->prepareTargetStatuses($this->lastTransUnit[$this->segmentInUnitPosition]);
69 69
 
70 70
                         //prepare for an eventual next cycle
71 71
                         $this->segmentInUnitPosition++;
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
                     }
74 74
 
75 75
                     // Warning, this is NOT an elseif
76
-                    if ( $k != 'conf' ) {
76
+                    if ($k != 'conf') {
77 77
                         //put also the current attribute in it if it is not a "conf" attribute
78 78
                         $tag .= "$k=\"$v\" ";
79 79
                     }
@@ -86,29 +86,29 @@  discard block
 block discarded – undo
86 86
             // this logic helps detecting empty tags
87 87
             // get current position of SAX pointer in all the stream of data is has read so far:
88 88
             // it points at the end of current tag
89
-            $idx = xml_get_current_byte_index( $parser );
89
+            $idx = xml_get_current_byte_index($parser);
90 90
 
91 91
             // check whether the bounds of current tag are entirely in current buffer || the end of the current tag
92 92
             // is outside current buffer (in the latter case, it's in next buffer to be read by the while loop);
93 93
             // this check is necessary because we may have truncated a tag in half with current read,
94 94
             // and the other half may be encountered in the next buffer it will be passed
95
-            if ( isset( $this->currentBuffer[ $idx - $this->offset ] ) ) {
95
+            if (isset($this->currentBuffer[$idx - $this->offset])) {
96 96
                 // if this tag entire lenght fitted in the buffer, the last char must be the last
97 97
                 // symbol before the '>'; if it's an empty tag, it is assumed that it's a '/'
98 98
                 $tmp_offset = $idx - $this->offset;
99
-                $lastChar   = $this->currentBuffer[ $tmp_offset ];
99
+                $lastChar   = $this->currentBuffer[$tmp_offset];
100 100
             } else {
101 101
                 //if it's out, simple use the last character of the chunk
102 102
                 $tmp_offset = $this->len - 1;
103
-                $lastChar   = $this->currentBuffer[ $tmp_offset ];
103
+                $lastChar   = $this->currentBuffer[$tmp_offset];
104 104
             }
105 105
 
106 106
             // trim last space
107
-            $tag = rtrim( $tag );
107
+            $tag = rtrim($tag);
108 108
 
109 109
             // detect empty tag
110
-            $this->isEmpty = ( $lastChar == '/' || $name == 'x' );
111
-            if ( $this->isEmpty ) {
110
+            $this->isEmpty = ($lastChar == '/' || $name == 'x');
111
+            if ($this->isEmpty) {
112 112
                 $tag .= '/';
113 113
             }
114 114
 
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
             $tag .= ">";
117 117
 
118 118
             // set a a Buffer for the segSource Source tag
119
-            if ( 'source' == $name
119
+            if ('source' == $name
120 120
                     || 'seg-source' === $name
121 121
                     || $this->bufferIsActive
122 122
                     || 'value' === $name
@@ -125,19 +125,19 @@  discard block
 block discarded – undo
125 125
                     || 'ph' === $name
126 126
                     || 'st' === $name
127 127
                     || 'note' === $name
128
-                    || 'context' === $name ) { // we are opening a critical CDATA section
128
+                    || 'context' === $name) { // we are opening a critical CDATA section
129 129
 
130 130
                 // WARNING BECAUSE SOURCE AND SEG-SOURCE TAGS CAN BE EMPTY IN SOME CASES!!!!!
131 131
                 // so check for isEmpty also in conjunction with name
132
-                if ( $this->isEmpty && ( 'source' == $name || 'seg-source' == $name ) ) {
133
-                    $this->postProcAndFlush( $this->outputFP, $tag );
132
+                if ($this->isEmpty && ('source' == $name || 'seg-source' == $name)) {
133
+                    $this->postProcAndFlush($this->outputFP, $tag);
134 134
                 } else {
135 135
                     //these are NOT source/seg-source/value empty tags, THERE IS A CONTENT, write it in buffer
136 136
                     $this->bufferIsActive = true;
137
-                    $this->CDATABuffer    .= $tag;
137
+                    $this->CDATABuffer .= $tag;
138 138
                 }
139 139
             } else {
140
-                $this->postProcAndFlush( $this->outputFP, $tag );
140
+                $this->postProcAndFlush($this->outputFP, $tag);
141 141
             }
142 142
         }
143 143
     }
@@ -150,19 +150,19 @@  discard block
 block discarded – undo
150 150
      *
151 151
      * @return string
152 152
      */
153
-    protected function prepareTranslation( $seg, $transUnitTranslation = "" ) {
153
+    protected function prepareTranslation($seg, $transUnitTranslation = "") {
154 154
         $endTags = "";
155 155
 
156
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
157
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
158
-        $dataRefMap  = ( isset( $seg[ 'data_ref_map' ] ) && $seg[ 'data_ref_map' ] !== null ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : [];
156
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
157
+        $translation = Strings::removeDangerousChars($seg ['translation']);
158
+        $dataRefMap  = (isset($seg['data_ref_map']) && $seg['data_ref_map'] !== null) ? Strings::jsonToArray($seg['data_ref_map']) : [];
159 159
 
160
-        if ( is_null( $seg [ 'translation' ] ) || $seg [ 'translation' ] == '' ) {
160
+        if (is_null($seg ['translation']) || $seg ['translation'] == '') {
161 161
             $translation = $segment;
162 162
         } else {
163
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
163
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
164 164
                 $error = (isset($seg['error'])) ? $seg['error'] : null;
165
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) {
165
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) {
166 166
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
167 167
                 }
168 168
             }
@@ -171,20 +171,20 @@  discard block
 block discarded – undo
171 171
         // for Trados the trailing spaces after </mrk> are meaningful
172 172
         // so we trim the translation from Matecat DB and add them after </mrk>
173 173
         $trailingSpaces = '';
174
-        for ( $s = 0; $s < Strings::getTheNumberOfTrailingSpaces( $translation ); $s++ ) {
174
+        for ($s = 0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++) {
175 175
             $trailingSpaces .= ' ';
176 176
         }
177 177
 
178
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
179
-            if ( $this->targetLang === 'ja-JP' ) {
180
-                $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] );
178
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
179
+            if ($this->targetLang === 'ja-JP') {
180
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
181 181
             }
182 182
 
183
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces;
183
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces;
184 184
         }
185 185
 
186 186
         // we need to trim succ_tags here because we already added the trailing spaces after </mrk>
187
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $translation . $endTags . ltrim( $seg[ 'succ_tags' ] );
187
+        $transUnitTranslation .= $seg['prev_tags'] . $translation . $endTags . ltrim($seg['succ_tags']);
188 188
 
189 189
         return $transUnitTranslation;
190 190
     }
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
      *
195 195
      * @return string
196 196
      */
197
-    protected function prepareTargetStatuses( $segment ) {
197
+    protected function prepareTargetStatuses($segment) {
198 198
         $statusMap = [
199 199
                 'NEW'        => '',
200 200
                 'DRAFT'      => 'Draft',
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
                 'REJECTED'   => 'RejectedTranslation',
204 204
         ];
205 205
 
206
-        return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" ";
206
+        return "conf=\"{$statusMap[$segment['status']]}\" ";
207 207
     }
208 208
 
209 209
     /**
@@ -213,8 +213,8 @@  discard block
 block discarded – undo
213 213
      *
214 214
      * @return array
215 215
      */
216
-    protected function setTransUnitState( $seg, $state_prop, $lastMrkState ) {
217
-        return [ null, null ];
216
+    protected function setTransUnitState($seg, $state_prop, $lastMrkState) {
217
+        return [null, null];
218 218
     }
219 219
 
220 220
     /**
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      *
224 224
      * @return string
225 225
      */
226
-    protected function getWordCountGroup( $raw_word_count, $eq_word_count ) {
226
+    protected function getWordCountGroup($raw_word_count, $eq_word_count) {
227 227
         return '';
228 228
     }
229 229
 }
Please login to merge, or discard this patch.
src/XliffReplacer/XliffSdl.php 1 patch
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -16,13 +16,13 @@  discard block
 block discarded – undo
16 16
     /**
17 17
      * @inheritDoc
18 18
      */
19
-    protected function tagOpen( $parser, $name, $attr ) {
19
+    protected function tagOpen($parser, $name, $attr) {
20 20
 
21
-        $this->handleOpenUnit( $name, $attr );
21
+        $this->handleOpenUnit($name, $attr);
22 22
 
23 23
         // check if we are entering into a <target>
24
-        if ( 'target' == $name ) {
25
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
24
+        if ('target' == $name) {
25
+            if ($this->currentTransUnitIsTranslatable === 'no') {
26 26
                 $this->inTarget = false;
27 27
             } else {
28 28
                 $this->inTarget = true;
@@ -30,18 +30,18 @@  discard block
 block discarded – undo
30 30
         }
31 31
 
32 32
         // reset Marker positions
33
-        if ( 'sdl:seg-defs' == $name ) {
33
+        if ('sdl:seg-defs' == $name) {
34 34
             $this->segmentInUnitPosition = 0;
35 35
         }
36 36
 
37 37
         // open buffer
38
-        if ( in_array( $name, $this->nodesToBuffer ) ) {
38
+        if (in_array($name, $this->nodesToBuffer)) {
39 39
             $this->bufferIsActive = true;
40 40
         }
41 41
 
42 42
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
43 43
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
44
-        if ( !$this->inTarget ) {
44
+        if (!$this->inTarget) {
45 45
 
46 46
             // costruct tag
47 47
             $tag = "<$name ";
@@ -51,16 +51,16 @@  discard block
 block discarded – undo
51 51
             // so the check on it's name is not enough
52 52
             $_sdlStatus_confWritten = false;
53 53
 
54
-            foreach ( $attr as $k => $v ) {
54
+            foreach ($attr as $k => $v) {
55 55
 
56 56
                 // if tag name is file, we must replace the target-language attribute
57
-                if ( $name == 'file' && $k == 'target-language' && !empty( $this->targetLang ) ) {
57
+                if ($name == 'file' && $k == 'target-language' && !empty($this->targetLang)) {
58 58
                     //replace Target language with job language provided from constructor
59 59
                     $tag .= "$k=\"$this->targetLang\" ";
60 60
                 } else {
61 61
                     //normal tag flux, put attributes in it
62 62
                     // Warning, this is NOT an elseif
63
-                    if ( $k != 'conf' ) {
63
+                    if ($k != 'conf') {
64 64
                         //put also the current attribute in it if it is not a "conf" attribute
65 65
                         $tag .= "$k=\"$v\" ";
66 66
                     }
@@ -69,11 +69,11 @@  discard block
 block discarded – undo
69 69
 
70 70
             $seg = $this->getCurrentSegment();
71 71
 
72
-            if ( 'sdl:seg' == $name && !empty( $seg ) and isset( $seg[ 'sid' ] ) ) {
73
-                $tag .= $this->prepareTargetStatuses( $seg );
72
+            if ('sdl:seg' == $name && !empty($seg) and isset($seg['sid'])) {
73
+                $tag .= $this->prepareTargetStatuses($seg);
74 74
             }
75 75
 
76
-            $this->checkForSelfClosedTagAndFlush( $parser, $tag );
76
+            $this->checkForSelfClosedTagAndFlush($parser, $tag);
77 77
 
78 78
         }
79 79
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      *
85 85
      * @return string
86 86
      */
87
-    protected function prepareTargetStatuses( $segment ): string {
87
+    protected function prepareTargetStatuses($segment): string {
88 88
         $statusMap = [
89 89
                 'NEW'        => '',
90 90
                 'DRAFT'      => 'Draft',
@@ -93,22 +93,22 @@  discard block
 block discarded – undo
93 93
                 'REJECTED'   => 'RejectedTranslation',
94 94
         ];
95 95
 
96
-        return "conf=\"{$statusMap[ $segment[ 'status' ] ]}\" ";
96
+        return "conf=\"{$statusMap[$segment['status']]}\" ";
97 97
     }
98 98
 
99
-    protected function rebuildMarks( array $seg, string $translation ): string {
99
+    protected function rebuildMarks(array $seg, string $translation): string {
100 100
 
101 101
         $trailingSpaces = '';
102
-        for ( $s = 0; $s < Strings::getTheNumberOfTrailingSpaces( $translation ); $s++ ) {
102
+        for ($s = 0; $s < Strings::getTheNumberOfTrailingSpaces($translation); $s++) {
103 103
             $trailingSpaces .= ' ';
104 104
         }
105 105
 
106
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
107
-            if ( $this->targetLang === 'ja-JP' ) {
108
-                $seg[ 'mrk_succ_tags' ] = ltrim( $seg[ 'mrk_succ_tags' ] );
106
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
107
+            if ($this->targetLang === 'ja-JP') {
108
+                $seg['mrk_succ_tags'] = ltrim($seg['mrk_succ_tags']);
109 109
             }
110 110
 
111
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . rtrim( $translation ) . $seg[ 'mrk_succ_tags' ] . "</mrk>" . $trailingSpaces;
111
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . rtrim($translation) . $seg['mrk_succ_tags'] . "</mrk>" . $trailingSpaces;
112 112
         }
113 113
 
114 114
         return $translation;
Please login to merge, or discard this patch.