Passed
Pull Request — master (#95)
by Mauro
06:03 queued 02:57
created
src/XliffReplacer/Xliff12.php 1 patch
Spacing   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -36,27 +36,27 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * @var string
38 38
      */
39
-    protected string $namespace = "mtc";       // Custom namespace
39
+    protected string $namespace = "mtc"; // Custom namespace
40 40
 
41 41
     /**
42 42
      * @inheritDoc
43 43
      */
44
-    protected function tagOpen( $parser, string $name, array $attr ) {
44
+    protected function tagOpen($parser, string $name, array $attr) {
45 45
 
46
-        $this->handleOpenUnit( $name, $attr );
46
+        $this->handleOpenUnit($name, $attr);
47 47
 
48
-        $this->trySetAltTrans( $name );;
49
-        $this->checkSetInTarget( $name );
48
+        $this->trySetAltTrans($name); ;
49
+        $this->checkSetInTarget($name);
50 50
 
51 51
         // open buffer
52
-        $this->setInBuffer( $name );
52
+        $this->setInBuffer($name);
53 53
 
54 54
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
55 55
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
56
-        if ( !$this->inTarget ) {
56
+        if (!$this->inTarget) {
57 57
 
58 58
             // We need bufferIsActive for not target nodes with currentTransUnitIsTranslatable = 'NO'
59
-            if($name === 'target' and $this->currentTransUnitIsTranslatable === 'no'){
59
+            if ($name === 'target' and $this->currentTransUnitIsTranslatable === 'no') {
60 60
                 $this->bufferIsActive = true;
61 61
             }
62 62
 
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
             // construct tag
66 66
             $tag .= "<$name ";
67 67
 
68
-            foreach ( $attr as $k => $v ) {
68
+            foreach ($attr as $k => $v) {
69 69
 
70 70
                 //if tag name is file, we must replace the target-language attribute
71
-                if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) {
71
+                if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) {
72 72
                     //replace Target language with job language provided from constructor
73 73
                     $tag .= "$k=\"$this->targetLang\" ";
74 74
                 } else {
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 
80 80
             $seg = $this->getCurrentSegment();
81 81
 
82
-            if ( $name === $this->tuTagName && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) {
82
+            if ($name === $this->tuTagName && !empty($seg) && isset($seg['sid'])) {
83 83
 
84 84
                 // add `help-id` to xliff v.1*
85
-                if ( strpos( $tag, 'help-id' ) === false ) {
86
-                    if ( !empty( $seg[ 'sid' ] ) ) {
87
-                        $tag .= "help-id=\"{$seg[ 'sid' ]}\" ";
85
+                if (strpos($tag, 'help-id') === false) {
86
+                    if (!empty($seg['sid'])) {
87
+                        $tag .= "help-id=\"{$seg['sid']}\" ";
88 88
                     }
89 89
                 }
90 90
 
91 91
             }
92 92
 
93
-            $tag = $this->handleOpenXliffTag( $name, $attr, $tag );
93
+            $tag = $this->handleOpenXliffTag($name, $attr, $tag);
94 94
 
95
-            $this->checkForSelfClosedTagAndFlush( $parser, $tag );
95
+            $this->checkForSelfClosedTagAndFlush($parser, $tag);
96 96
 
97 97
         }
98 98
 
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
     /**
103 103
      * @inheritDoc
104 104
      */
105
-    protected function tagClose( $parser, string $name ) {
105
+    protected function tagClose($parser, string $name) {
106 106
         $tag = '';
107 107
 
108 108
         /**
@@ -111,23 +111,23 @@  discard block
 block discarded – undo
111 111
          *
112 112
          * self::tagOpen method
113 113
          */
114
-        if ( !$this->isEmpty ) {
114
+        if (!$this->isEmpty) {
115 115
 
116 116
             // write closing tag if is not a target
117 117
             // EXCLUDE the target nodes with currentTransUnitIsTranslatable = 'NO'
118
-            if ( !$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no' ) {
118
+            if (!$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no') {
119 119
                 $tag = "</$name>";
120 120
             }
121 121
 
122
-            if ( 'target' == $name && !$this->inAltTrans ) {
122
+            if ('target' == $name && !$this->inAltTrans) {
123 123
 
124
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
124
+                if (isset($this->transUnits[$this->currentTransUnitId])) {
125 125
 
126 126
                     // get translation of current segment, by indirect indexing: id -> positional index -> segment
127 127
                     // actually there may be more than one segment to that ID if there are two mrk of the same source segment
128 128
                     $tag = $this->rebuildTarget();
129 129
 
130
-                } elseif( !empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no' ) {
130
+                } elseif (!empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no') {
131 131
 
132 132
                     // These are target nodes with currentTransUnitIsTranslatable = 'NO'
133 133
                     $this->bufferIsActive = false;
@@ -138,45 +138,45 @@  discard block
 block discarded – undo
138 138
                 $this->targetWasWritten = true;
139 139
                 // signal we are leaving a target
140 140
                 $this->inTarget = false;
141
-                $this->postProcAndFlush( $this->outputFP, $tag, true );
141
+                $this->postProcAndFlush($this->outputFP, $tag, true);
142 142
 
143
-            } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section
143
+            } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section
144 144
 
145 145
                 $this->bufferIsActive = false;
146 146
                 $tag                  = $this->CDATABuffer . "</$name>";
147 147
                 $this->CDATABuffer    = "";
148 148
 
149 149
                 //flush to the pointer
150
-                $this->postProcAndFlush( $this->outputFP, $tag );
150
+                $this->postProcAndFlush($this->outputFP, $tag);
151 151
 
152
-            } elseif ( $name === $this->tuTagName ) {
152
+            } elseif ($name === $this->tuTagName) {
153 153
 
154 154
                 $tag = "";
155 155
 
156 156
                 // handling </trans-unit> closure
157
-                if ( !$this->targetWasWritten ) {
157
+                if (!$this->targetWasWritten) {
158 158
 
159
-                    if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
159
+                    if (isset($this->transUnits[$this->currentTransUnitId])) {
160 160
                         $tag = $this->rebuildTarget();
161 161
                     } else {
162
-                        $tag = $this->createTargetTag( "", "" );
162
+                        $tag = $this->createTargetTag("", "");
163 163
                     }
164 164
 
165 165
                 }
166 166
 
167
-                $tag                    .= "</$this->tuTagName>";
167
+                $tag .= "</$this->tuTagName>";
168 168
                 $this->targetWasWritten = false;
169
-                $this->postProcAndFlush( $this->outputFP, $tag );
169
+                $this->postProcAndFlush($this->outputFP, $tag);
170 170
 
171
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
171
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
172 172
                 $this->CDATABuffer .= "</$name>";
173 173
                 // Do NOT Flush
174 174
             } else { //generic tag closure do Nothing
175 175
                 // flush to pointer
176
-                $this->postProcAndFlush( $this->outputFP, $tag );
176
+                $this->postProcAndFlush($this->outputFP, $tag);
177 177
             }
178 178
 
179
-        } elseif ( in_array( $name, $this->nodesToBuffer ) ) {
179
+        } elseif (in_array($name, $this->nodesToBuffer)) {
180 180
 
181 181
             $this->isEmpty        = false;
182 182
             $this->bufferIsActive = false;
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
             $this->CDATABuffer    = "";
185 185
 
186 186
             //flush to the pointer
187
-            $this->postProcAndFlush( $this->outputFP, $tag );
187
+            $this->postProcAndFlush($this->outputFP, $tag);
188 188
 
189 189
         } else {
190 190
             //ok, nothing to be done; reset flag for next coming tag
@@ -192,10 +192,10 @@  discard block
 block discarded – undo
192 192
         }
193 193
 
194 194
         // try to signal that we are leaving a target
195
-        $this->tryUnsetAltTrans( $name );
195
+        $this->tryUnsetAltTrans($name);
196 196
 
197 197
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
198
-        if ( $this->tuTagName === $name ) {
198
+        if ($this->tuTagName === $name) {
199 199
             $this->currentTransUnitIsTranslatable = null;
200 200
             $this->inTU                           = false;
201 201
             $this->hasWrittenCounts               = false;
@@ -212,31 +212,31 @@  discard block
 block discarded – undo
212 212
      *
213 213
      * @return string
214 214
      */
215
-    protected function prepareTranslation( array $seg, string $transUnitTranslation = "" ): string {
215
+    protected function prepareTranslation(array $seg, string $transUnitTranslation = ""): string {
216 216
 
217
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
218
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
217
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
218
+        $translation = Strings::removeDangerousChars($seg ['translation']);
219 219
 
220
-        if ( $seg [ 'translation' ] == '' ) {
220
+        if ($seg ['translation'] == '') {
221 221
             $translation = $segment;
222 222
         } else {
223
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
224
-                $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null;
225
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, [], $error ) ) {
223
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
224
+                $error = (!empty($seg['error'])) ? $seg['error'] : null;
225
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, [], $error)) {
226 226
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
227 227
                 }
228 228
             }
229 229
         }
230 230
 
231
-        $transUnitTranslation .= $seg[ 'prev_tags' ] . $this->rebuildMarks( $seg, $translation ) . ltrim( $seg[ 'succ_tags' ] );
231
+        $transUnitTranslation .= $seg['prev_tags'] . $this->rebuildMarks($seg, $translation) . ltrim($seg['succ_tags']);
232 232
 
233 233
         return $transUnitTranslation;
234 234
     }
235 235
 
236
-    protected function rebuildMarks( array $seg, string $translation ): string {
236
+    protected function rebuildMarks(array $seg, string $translation): string {
237 237
 
238
-        if ( $seg[ 'mrk_id' ] !== null && $seg[ 'mrk_id' ] != '' ) {
239
-            $translation = "<mrk mid=\"" . $seg[ 'mrk_id' ] . "\" mtype=\"seg\">" . $seg[ 'mrk_prev_tags' ] . $translation . $seg[ 'mrk_succ_tags' ] . "</mrk>";
238
+        if ($seg['mrk_id'] !== null && $seg['mrk_id'] != '') {
239
+            $translation = "<mrk mid=\"" . $seg['mrk_id'] . "\" mtype=\"seg\">" . $seg['mrk_prev_tags'] . $translation . $seg['mrk_succ_tags'] . "</mrk>";
240 240
         }
241 241
 
242 242
         return $translation;
@@ -251,10 +251,10 @@  discard block
 block discarded – undo
251 251
      *
252 252
      * @return string
253 253
      */
254
-    protected function createTargetTag( string $translation, string $stateProp ): string {
254
+    protected function createTargetTag(string $translation, string $stateProp): string {
255 255
         $targetLang = ' xml:lang="' . $this->targetLang . '"';
256 256
         $tag        = "<target $targetLang $stateProp>$translation</target>";
257
-        $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>';
257
+        $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>';
258 258
 
259 259
         return $tag;
260 260
 
@@ -270,7 +270,7 @@  discard block
 block discarded – undo
270 270
         // we must reset the lastMrkId found because this is a new segment.
271 271
         $lastMrkId = -1;
272 272
 
273
-        foreach ( $this->lastTransUnit as $pos => $seg ) {
273
+        foreach ($this->lastTransUnit as $pos => $seg) {
274 274
 
275 275
             /*
276 276
              * This routine works to respect the positional orders of markers.
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
              * pre-assign zero to the new mrk if this is the first one ( in this segment )
284 284
              * If it is null leave it NULL
285 285
              */
286
-            if ( (int)$seg[ "mrk_id" ] < 0 && $seg[ "mrk_id" ] !== null ) {
287
-                $seg[ "mrk_id" ] = 0;
286
+            if ((int)$seg["mrk_id"] < 0 && $seg["mrk_id"] !== null) {
287
+                $seg["mrk_id"] = 0;
288 288
             }
289 289
 
290 290
             /*
@@ -293,39 +293,39 @@  discard block
 block discarded – undo
293 293
              * ( null <= -1 ) === true
294 294
              * so, cast to int
295 295
              */
296
-            if ( (int)$seg[ "mrk_id" ] <= $lastMrkId ) {
296
+            if ((int)$seg["mrk_id"] <= $lastMrkId) {
297 297
                 break;
298 298
             }
299 299
 
300 300
             // update counts
301
-            if ( !empty( $seg ) ) {
302
-                $this->updateSegmentCounts( $seg );
301
+            if (!empty($seg)) {
302
+                $this->updateSegmentCounts($seg);
303 303
             }
304 304
 
305 305
             // delete translations so the prepareSegment
306 306
             // will put source content in target tag
307
-            if ( $this->sourceInTarget ) {
308
-                $seg[ 'translation' ] = '';
307
+            if ($this->sourceInTarget) {
308
+                $seg['translation'] = '';
309 309
                 $this->resetCounts();
310 310
             }
311 311
 
312 312
             // append $translation
313
-            $translation = $this->prepareTranslation( $seg, $translation );
313
+            $translation = $this->prepareTranslation($seg, $translation);
314 314
 
315
-            $lastMrkId = $seg[ "mrk_id" ];
315
+            $lastMrkId = $seg["mrk_id"];
316 316
 
317
-            [ $stateProp, $lastMrkState ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ], $lastMrkState );
317
+            [$stateProp, $lastMrkState] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status'], $lastMrkState);
318 318
 
319 319
         }
320 320
 
321 321
         //append translation
322
-        return $this->createTargetTag( $translation, $stateProp );
322
+        return $this->createTargetTag($translation, $stateProp);
323 323
 
324 324
     }
325 325
 
326 326
     protected function getCurrentSegment(): array {
327
-        if ( $this->currentTransUnitIsTranslatable !== 'no' && isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
328
-            return $this->segments[ $this->transUnits[ $this->currentTransUnitId ][ 0 ] ]; // TODO try to understand why here is needed to override the method and set 0 index hardcoded
327
+        if ($this->currentTransUnitIsTranslatable !== 'no' && isset($this->transUnits[$this->currentTransUnitId])) {
328
+            return $this->segments[$this->transUnits[$this->currentTransUnitId][0]]; // TODO try to understand why here is needed to override the method and set 0 index hardcoded
329 329
         }
330 330
 
331 331
         return [];
Please login to merge, or discard this patch.
src/XliffReplacer/Xliff20.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     /**
21 21
      * @var bool
22 22
      */
23
-    protected bool $unitContainsMda = false;   // check if <unit> already contains a <mda:metadata> (forXliff v 2.*)
23
+    protected bool $unitContainsMda = false; // check if <unit> already contains a <mda:metadata> (forXliff v 2.*)
24 24
 
25 25
     /**
26 26
      * @var string
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
     /**
36 36
      * @var string
37 37
      */
38
-    protected string $namespace = "matecat";       // Custom namespace
38
+    protected string $namespace = "matecat"; // Custom namespace
39 39
 
40 40
     /**
41 41
      * @var array
@@ -51,26 +51,26 @@  discard block
 block discarded – undo
51 51
     /**
52 52
      * @inheritDoc
53 53
      */
54
-    protected function tagOpen( $parser, string $name, array $attr ) {
54
+    protected function tagOpen($parser, string $name, array $attr) {
55 55
 
56
-        $this->handleOpenUnit( $name, $attr );
56
+        $this->handleOpenUnit($name, $attr);
57 57
 
58
-        if ( 'mda:metadata' === $name ) {
58
+        if ('mda:metadata' === $name) {
59 59
             $this->unitContainsMda = true;
60 60
         }
61 61
 
62
-        $this->trySetAltTrans( $name );;
63
-        $this->checkSetInTarget( $name );
62
+        $this->trySetAltTrans($name); ;
63
+        $this->checkSetInTarget($name);
64 64
 
65 65
         // open buffer
66
-        $this->setInBuffer( $name );
66
+        $this->setInBuffer($name);
67 67
 
68 68
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
69 69
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
70
-        if ( !$this->inTarget ) {
70
+        if (!$this->inTarget) {
71 71
 
72 72
             // We need bufferIsActive for not target nodes with currentTransUnitIsTranslatable = 'NO'
73
-            if($name === 'target' and $this->currentTransUnitIsTranslatable === 'no'){
73
+            if ($name === 'target' and $this->currentTransUnitIsTranslatable === 'no') {
74 74
                 $this->bufferIsActive = true;
75 75
             }
76 76
 
@@ -94,48 +94,48 @@  discard block
 block discarded – undo
94 94
             //
95 95
             // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit
96 96
             //
97
-            if ( in_array( $name, [ 'notes', 'originalData', 'segment', 'ignorable' ] ) &&
97
+            if (in_array($name, ['notes', 'originalData', 'segment', 'ignorable']) &&
98 98
                     $this->unitContainsMda === false &&
99
-                    !empty( $this->transUnits[ $this->currentTransUnitId ] ) &&
99
+                    !empty($this->transUnits[$this->currentTransUnitId]) &&
100 100
                     !$this->hasWrittenCounts
101 101
             ) {
102 102
                 // we need to update counts here
103 103
                 $this->updateCounts();
104 104
                 $this->hasWrittenCounts = true;
105
-                $tag                    .= $this->getWordCountGroupForXliffV2();
105
+                $tag .= $this->getWordCountGroupForXliffV2();
106 106
                 $this->unitContainsMda  = true;
107 107
             }
108 108
 
109 109
             // construct tag
110 110
             $tag .= "<$name ";
111 111
 
112
-            foreach ( $attr as $k => $v ) {
112
+            foreach ($attr as $k => $v) {
113 113
                 //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute
114
-                if ( $k != 'state' ) {
114
+                if ($k != 'state') {
115 115
                     $tag .= "$k=\"$v\" ";
116 116
                 }
117 117
             }
118 118
 
119 119
             $seg = $this->getCurrentSegment();
120 120
 
121
-            if ( $name === $this->tuTagName && !empty( $seg ) && isset( $seg[ 'sid' ] ) ) {
121
+            if ($name === $this->tuTagName && !empty($seg) && isset($seg['sid'])) {
122 122
 
123 123
                 // add `matecat:segment-id` to xliff v.2*
124
-                if ( strpos( $tag, 'matecat:segment-id' ) === false ) {
125
-                    $tag .= "matecat:segment-id=\"{$seg[ 'sid' ]}\" ";
124
+                if (strpos($tag, 'matecat:segment-id') === false) {
125
+                    $tag .= "matecat:segment-id=\"{$seg['sid']}\" ";
126 126
                 }
127 127
 
128 128
             }
129 129
 
130 130
             // replace state for xliff v2
131
-            if ( 'segment' === $name ) { // add state to segment in Xliff v2
132
-                [ $stateProp, ] = StatusToStateAttribute::getState( $this->xliffVersion, $seg[ 'status' ] );
131
+            if ('segment' === $name) { // add state to segment in Xliff v2
132
+                [$stateProp, ] = StatusToStateAttribute::getState($this->xliffVersion, $seg['status']);
133 133
                 $tag .= $stateProp;
134 134
             }
135 135
 
136
-            $tag = $this->handleOpenXliffTag( $name, $attr, $tag );
136
+            $tag = $this->handleOpenXliffTag($name, $attr, $tag);
137 137
 
138
-            $this->checkForSelfClosedTagAndFlush( $parser, $tag );
138
+            $this->checkForSelfClosedTagAndFlush($parser, $tag);
139 139
 
140 140
         }
141 141
 
@@ -148,10 +148,10 @@  discard block
 block discarded – undo
148 148
      *
149 149
      * @return string
150 150
      */
151
-    protected function handleOpenXliffTag( string $name, array $attr, string $tag ): string {
152
-        $tag = parent::handleOpenXliffTag( $name, $attr, $tag );
151
+    protected function handleOpenXliffTag(string $name, array $attr, string $tag): string {
152
+        $tag = parent::handleOpenXliffTag($name, $attr, $tag);
153 153
         // add oasis xliff 20 namespace
154
-        if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) {
154
+        if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) {
155 155
             $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"';
156 156
         }
157 157
 
@@ -161,7 +161,7 @@  discard block
 block discarded – undo
161 161
     /**
162 162
      * @inheritDoc
163 163
      */
164
-    protected function tagClose( $parser, string $name ) {
164
+    protected function tagClose($parser, string $name) {
165 165
         $tag = '';
166 166
 
167 167
         /**
@@ -170,39 +170,39 @@  discard block
 block discarded – undo
170 170
          *
171 171
          * self::tagOpen method
172 172
          */
173
-        if ( !$this->isEmpty ) {
173
+        if (!$this->isEmpty) {
174 174
 
175 175
             // write closing tag if is not a target
176 176
             // EXCLUDE the target nodes with currentTransUnitIsTranslatable = 'NO'
177
-            if ( !$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no' ) {
177
+            if (!$this->inTarget and $this->currentTransUnitIsTranslatable !== 'no') {
178 178
                 $tag = "</$name>";
179 179
             }
180 180
 
181
-            if ( 'target' == $name && !$this->inAltTrans ) {
181
+            if ('target' == $name && !$this->inAltTrans) {
182 182
 
183
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) ) {
183
+                if (isset($this->transUnits[$this->currentTransUnitId])) {
184 184
 
185 185
                     $seg = $this->getCurrentSegment();
186 186
 
187 187
                     // update counts
188
-                    if ( !$this->hasWrittenCounts && !empty( $seg ) ) {
189
-                        $this->updateSegmentCounts( $seg );
188
+                    if (!$this->hasWrittenCounts && !empty($seg)) {
189
+                        $this->updateSegmentCounts($seg);
190 190
                     }
191 191
 
192 192
                     // delete translations so the prepareSegment
193 193
                     // will put source content in target tag
194
-                    if ( $this->sourceInTarget ) {
195
-                        $seg[ 'translation' ] = '';
194
+                    if ($this->sourceInTarget) {
195
+                        $seg['translation'] = '';
196 196
                         $this->resetCounts();
197 197
                     }
198 198
 
199 199
                     // append $translation
200
-                    $translation = $this->prepareTranslation( $seg );
200
+                    $translation = $this->prepareTranslation($seg);
201 201
 
202 202
                     //append translation
203 203
                     $tag = "<target>$translation</target>";
204 204
 
205
-                } elseif( !empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no' ) {
205
+                } elseif (!empty($this->CDATABuffer) and $this->currentTransUnitIsTranslatable === 'no') {
206 206
 
207 207
                     // These are target nodes with currentTransUnitIsTranslatable = 'NO'
208 208
                     $this->bufferIsActive = false;
@@ -213,22 +213,22 @@  discard block
 block discarded – undo
213 213
                 // signal we are leaving a target
214 214
                 $this->targetWasWritten = true;
215 215
                 $this->inTarget         = false;
216
-                $this->postProcAndFlush( $this->outputFP, $tag, true );
216
+                $this->postProcAndFlush($this->outputFP, $tag, true);
217 217
 
218
-            } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section
218
+            } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section
219 219
 
220 220
                 $this->bufferIsActive = false;
221 221
 
222 222
                 // only for Xliff 2.*
223 223
                 // write here <mda:metaGroup> and <mda:meta> if already present in the <unit>
224
-                if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) {
224
+                if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) {
225 225
 
226 226
                     // we need to update counts here
227 227
                     $this->updateCounts();
228 228
                     $this->hasWrittenCounts = true;
229 229
 
230 230
                     $tag = $this->CDATABuffer;
231
-                    $tag .= $this->getWordCountGroupForXliffV2( false );
231
+                    $tag .= $this->getWordCountGroupForXliffV2(false);
232 232
                     $tag .= "    </mda:metadata>";
233 233
 
234 234
                 } else {
@@ -238,19 +238,19 @@  discard block
 block discarded – undo
238 238
                 $this->CDATABuffer = "";
239 239
 
240 240
                 //flush to the pointer
241
-                $this->postProcAndFlush( $this->outputFP, $tag );
241
+                $this->postProcAndFlush($this->outputFP, $tag);
242 242
 
243
-            } elseif ( 'segment' === $name ) {
243
+            } elseif ('segment' === $name) {
244 244
 
245 245
                 // only for Xliff 2.*
246 246
                 // if segment has no <target> add it BEFORE </segment>
247
-                if ( !$this->targetWasWritten ) {
247
+                if (!$this->targetWasWritten) {
248 248
 
249 249
                     $seg = $this->getCurrentSegment();
250 250
 
251
-                    if ( isset( $seg[ 'translation' ] ) ) {
251
+                    if (isset($seg['translation'])) {
252 252
 
253
-                        $translation = $this->prepareTranslation( $seg );
253
+                        $translation = $this->prepareTranslation($seg);
254 254
                         // replace the tag
255 255
                         $tag = "<target>$translation</target>";
256 256
 
@@ -263,19 +263,19 @@  discard block
 block discarded – undo
263 263
                 // update segmentPositionInTu
264 264
                 $this->segmentInUnitPosition++;
265 265
 
266
-                $this->postProcAndFlush( $this->outputFP, $tag );
266
+                $this->postProcAndFlush($this->outputFP, $tag);
267 267
 
268 268
                 // we are leaving <segment>, reset $segmentHasTarget
269 269
                 $this->targetWasWritten = false;
270 270
 
271
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
271
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
272 272
                 $this->CDATABuffer .= "</$name>";
273 273
                 // Do NOT Flush
274 274
             } else { //generic tag closure do Nothing
275 275
                 // flush to pointer
276
-                $this->postProcAndFlush( $this->outputFP, $tag );
276
+                $this->postProcAndFlush($this->outputFP, $tag);
277 277
             }
278
-        } elseif ( in_array( $name, $this->nodesToBuffer ) ) {
278
+        } elseif (in_array($name, $this->nodesToBuffer)) {
279 279
 
280 280
             $this->isEmpty        = false;
281 281
             $this->bufferIsActive = false;
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             $this->CDATABuffer    = "";
284 284
 
285 285
             //flush to the pointer
286
-            $this->postProcAndFlush( $this->outputFP, $tag );
286
+            $this->postProcAndFlush($this->outputFP, $tag);
287 287
 
288 288
         } else {
289 289
             //ok, nothing to be done; reset flag for next coming tag
@@ -291,10 +291,10 @@  discard block
 block discarded – undo
291 291
         }
292 292
 
293 293
         // try to signal that we are leaving a target
294
-        $this->tryUnsetAltTrans( $name );
294
+        $this->tryUnsetAltTrans($name);
295 295
 
296 296
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
297
-        if ( $this->tuTagName === $name ) {
297
+        if ($this->tuTagName === $name) {
298 298
             $this->currentTransUnitIsTranslatable = null;
299 299
             $this->inTU                           = false;
300 300
             $this->unitContainsMda                = false;
@@ -310,8 +310,8 @@  discard block
 block discarded – undo
310 310
     private function updateCounts() {
311 311
 
312 312
         $seg = $this->getCurrentSegment();
313
-        if ( !empty( $seg ) ) {
314
-            $this->updateSegmentCounts( $seg );
313
+        if (!empty($seg)) {
314
+            $this->updateSegmentCounts($seg);
315 315
         }
316 316
 
317 317
     }
@@ -321,30 +321,30 @@  discard block
 block discarded – undo
321 321
      *
322 322
      * @return string
323 323
      */
324
-    private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string {
324
+    private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string {
325 325
 
326 326
         $this->mdaGroupCounter++;
327
-        $segments_count_array = $this->counts[ 'segments_count_array' ];
327
+        $segments_count_array = $this->counts['segments_count_array'];
328 328
 
329 329
         $tag = '';
330 330
 
331
-        if ( $withMetadataTag === true ) {
331
+        if ($withMetadataTag === true) {
332 332
             $tag .= '<mda:metadata>';
333 333
         }
334 334
 
335 335
         $index = 0;
336
-        foreach ( $segments_count_array as $segments_count_item ) {
336
+        foreach ($segments_count_array as $segments_count_item) {
337 337
 
338 338
             $id = 'word_count_tu.' . $this->currentTransUnitId . '.' . $index;
339 339
             $index++;
340 340
 
341 341
             $tag .= "    <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\">
342
-                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta>
343
-                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta>
342
+                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta>
343
+                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta>
344 344
                             </mda:metaGroup>";
345 345
         }
346 346
 
347
-        if ( $withMetadataTag === true ) {
347
+        if ($withMetadataTag === true) {
348 348
             $tag .= '</mda:metadata>';
349 349
         }
350 350
 
@@ -359,18 +359,18 @@  discard block
 block discarded – undo
359 359
      *
360 360
      * @return string
361 361
      */
362
-    protected function prepareTranslation( array $seg ): string {
362
+    protected function prepareTranslation(array $seg): string {
363 363
 
364
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
365
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
366
-        $dataRefMap  = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : [];
364
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
365
+        $translation = Strings::removeDangerousChars($seg ['translation']);
366
+        $dataRefMap  = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : [];
367 367
 
368
-        if ( $seg [ 'translation' ] == '' ) {
368
+        if ($seg ['translation'] == '') {
369 369
             $translation = $segment;
370 370
         } else {
371
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
372
-                $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null;
373
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) {
371
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
372
+                $error = (!empty($seg['error'])) ? $seg['error'] : null;
373
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) {
374 374
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
375 375
                 }
376 376
             }
Please login to merge, or discard this patch.