Passed
Pull Request — master (#90)
by Domenico
08:32
created
src/Utils/FlatData.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -8,14 +8,14 @@
 block discarded – undo
8 8
  * https://stackoverflow.com/questions/11427398/how-to-implode-array-with-key-and-value-without-foreach-in-php
9 9
  */
10 10
 class FlatData {
11
-    public static function flatArray( array $input = [], $separator_elements = ', ', $separator = ': ' ) {
12
-        return implode( $separator_elements, array_map(
13
-                function ( $v, $k, $s ) {
14
-                    return sprintf( "%s{$s}\"%s\"", $k, $v );
11
+    public static function flatArray(array $input = [], $separator_elements = ', ', $separator = ': ') {
12
+        return implode($separator_elements, array_map(
13
+                function($v, $k, $s) {
14
+                    return sprintf("%s{$s}\"%s\"", $k, $v);
15 15
                 },
16 16
                 $input,
17
-                array_keys( $input ),
18
-                array_fill( 0, count( $input ), $separator )
19
-        ) );
17
+                array_keys($input),
18
+                array_fill(0, count($input), $separator)
19
+        ));
20 20
     }
21 21
 }
Please login to merge, or discard this patch.
src/XliffParser/XliffParserFactory.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@
 block discarded – undo
12 12
      *
13 13
      * @return AbstractXliffParser
14 14
      */
15
-    public static function getInstance( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) {
15
+    public static function getInstance($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) {
16 16
         $parserClass = 'Matecat\\XliffParser\\XliffParser\\XliffParserV' . $xliffVersion;
17 17
 
18 18
         /** @var AbstractXliffParser $parser */
19
-        return new $parserClass( $xliffVersion, $xliffProprietary, $logger );
19
+        return new $parserClass($xliffVersion, $xliffProprietary, $logger);
20 20
     }
21 21
 }
Please login to merge, or discard this patch.
src/XliffReplacer/XliffReplacerCallbackInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,5 +11,5 @@
 block discarded – undo
11 11
      * @param null $error
12 12
      * @return bool
13 13
      */
14
-    public function thereAreErrors( $segmentId, $segment, $translation, array $dataRefMap = [], $error = null );
14
+    public function thereAreErrors($segmentId, $segment, $translation, array $dataRefMap = [], $error = null);
15 15
 }
Please login to merge, or discard this patch.
src/Utils/Strings.php 1 patch
Spacing   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
      * @return string
18 18
      * @throws Exception
19 19
      */
20
-    public static function cleanCDATA( $testString ) {
21
-        $cleanXMLContent = new SimpleXMLElement( '<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA );
20
+    public static function cleanCDATA($testString) {
21
+        $cleanXMLContent = new SimpleXMLElement('<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA);
22 22
 
23 23
         return $cleanXMLContent->__toString();
24 24
     }
@@ -28,28 +28,28 @@  discard block
 block discarded – undo
28 28
      *
29 29
      * @return bool
30 30
      */
31
-    public static function isJSON( $string ) {
32
-        if ( is_numeric( $string ) ) {
31
+    public static function isJSON($string) {
32
+        if (is_numeric($string)) {
33 33
             return false;
34 34
         }
35 35
 
36 36
         try {
37
-            $string = Strings::cleanCDATA( $string );
38
-        } catch ( Exception $e ) {
37
+            $string = Strings::cleanCDATA($string);
38
+        } catch (Exception $e) {
39 39
             return false;
40 40
         }
41 41
 
42
-        $string = trim( $string );
43
-        if ( empty( $string ) ) {
42
+        $string = trim($string);
43
+        if (empty($string)) {
44 44
             return false;
45 45
         }
46 46
 
47 47
         // String representation in json is "quoted", but we want to accept only object or arrays.
48 48
         // exclude strings and numbers and other primitive types
49
-        if ( in_array( $string [ 0 ], [ "{", "[" ] ) ) {
50
-            json_decode( $string );
49
+        if (in_array($string [0], ["{", "["])) {
50
+            json_decode($string);
51 51
 
52
-            return empty( self::getLastJsonError()[ 0 ] );
52
+            return empty(self::getLastJsonError()[0]);
53 53
         } else {
54 54
             return false; // Not accepted: string or primitive types.
55 55
         }
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
      *
62 62
      * @return array
63 63
      */
64
-    public static function jsonToArray( $string ) {
65
-        $decodedJSON = json_decode( $string, true );
64
+    public static function jsonToArray($string) {
65
+        $decodedJSON = json_decode($string, true);
66 66
 
67
-        return ( is_array( $decodedJSON ) ) ? $decodedJSON : [];
67
+        return (is_array($decodedJSON)) ? $decodedJSON : [];
68 68
     }
69 69
 
70 70
     /**
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
      */
76 76
     private static function raiseLastJsonException() {
77 77
 
78
-        list( $msg, $error ) = self::getLastJsonError();
78
+        list($msg, $error) = self::getLastJsonError();
79 79
 
80
-        if ( $error != JSON_ERROR_NONE ) {
81
-            throw new NotValidJSONException( $msg, $error );
80
+        if ($error != JSON_ERROR_NONE) {
81
+            throw new NotValidJSONException($msg, $error);
82 82
         }
83 83
 
84 84
     }
@@ -88,11 +88,11 @@  discard block
 block discarded – undo
88 88
      */
89 89
     private static function getLastJsonError() {
90 90
 
91
-        if ( function_exists( "json_last_error" ) ) {
91
+        if (function_exists("json_last_error")) {
92 92
 
93 93
             $error = json_last_error();
94 94
 
95
-            switch ( $error ) {
95
+            switch ($error) {
96 96
                 case JSON_ERROR_NONE:
97 97
                     $msg = null; # - No errors
98 98
                     break;
@@ -116,10 +116,10 @@  discard block
 block discarded – undo
116 116
                     break;
117 117
             }
118 118
 
119
-            return [ $msg, $error ];
119
+            return [$msg, $error];
120 120
         }
121 121
 
122
-        return [ null, JSON_ERROR_NONE ];
122
+        return [null, JSON_ERROR_NONE];
123 123
 
124 124
     }
125 125
 
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
      *
143 143
      * @return string
144 144
      */
145
-    public static function fixNonWellFormedXml( $content, $escapeStrings = true ) {
146
-        if ( self::$find_xliff_tags_reg === null ) {
145
+    public static function fixNonWellFormedXml($content, $escapeStrings = true) {
146
+        if (self::$find_xliff_tags_reg === null) {
147 147
             // Convert the list of tags in a regexp list, for example "g|x|bx|ex"
148 148
             $xliffTags           = XliffTags::$tags;
149
-            $xliff_tags_reg_list = implode( '|', $xliffTags );
149
+            $xliff_tags_reg_list = implode('|', $xliffTags);
150 150
             // Regexp to find all the XLIFF tags:
151 151
             //   </?               -> matches the tag start, for both opening and
152 152
             //                        closure tags (see the optional slash)
@@ -167,30 +167,30 @@  discard block
 block discarded – undo
167 167
         }
168 168
 
169 169
         // Find all the XLIFF tags
170
-        preg_match_all( self::$find_xliff_tags_reg, $content, $matches );
171
-        $tags = (array)$matches[ 0 ];
170
+        preg_match_all(self::$find_xliff_tags_reg, $content, $matches);
171
+        $tags = (array)$matches[0];
172 172
 
173 173
         // Prepare placeholders
174 174
         $tags_placeholders = [];
175
-        $tagsNum           = count( $tags );
176
-        for ( $i = 0; $i < $tagsNum; $i++ ) {
177
-            $tag                       = $tags[ $i ];
178
-            $tags_placeholders[ $tag ] = "#@!XLIFF-TAG-$i!@#";
175
+        $tagsNum           = count($tags);
176
+        for ($i = 0; $i < $tagsNum; $i++) {
177
+            $tag                       = $tags[$i];
178
+            $tags_placeholders[$tag] = "#@!XLIFF-TAG-$i!@#";
179 179
         }
180 180
 
181 181
         // Replace all XLIFF tags with placeholders that will not be escaped
182
-        foreach ( $tags_placeholders as $tag => $placeholder ) {
183
-            $content = str_replace( $tag, $placeholder, $content );
182
+        foreach ($tags_placeholders as $tag => $placeholder) {
183
+            $content = str_replace($tag, $placeholder, $content);
184 184
         }
185 185
 
186 186
         // Escape the string with the remaining non-XLIFF tags
187
-        if ( $escapeStrings ) {
188
-            $content = htmlspecialchars( $content, ENT_NOQUOTES, 'UTF-8', false );
187
+        if ($escapeStrings) {
188
+            $content = htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8', false);
189 189
         }
190 190
 
191 191
         // Put again in place the original XLIFF tags replacing placeholders
192
-        foreach ( $tags_placeholders as $tag => $placeholder ) {
193
-            $content = str_replace( $placeholder, $tag, $content );
192
+        foreach ($tags_placeholders as $tag => $placeholder) {
193
+            $content = str_replace($placeholder, $tag, $content);
194 194
         }
195 195
 
196 196
         return $content;
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
      *
202 202
      * @return string
203 203
      */
204
-    public static function removeDangerousChars( $string ) {
204
+    public static function removeDangerousChars($string) {
205 205
         // clean invalid xml entities ( characters with ascii < 32 and different from 0A, 0D and 09
206 206
         $regexpEntity = '/&#x(0[0-8BCEF]|1[\dA-F]|7F);/u';
207 207
 
208 208
         // remove binary chars in some xliff files
209 209
         $regexpAscii = '/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}]/u';
210 210
 
211
-        $string = preg_replace( $regexpAscii, '', $string );
212
-        $string = preg_replace( $regexpEntity, '', $string );
211
+        $string = preg_replace($regexpAscii, '', $string);
212
+        $string = preg_replace($regexpEntity, '', $string);
213 213
 
214
-        return !empty( $string ) || strlen( $string ) > 0 ? $string : "";
214
+        return !empty($string) || strlen($string) > 0 ? $string : "";
215 215
     }
216 216
 
217 217
     /**
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
      *
221 221
      * @return bool
222 222
      */
223
-    public static function contains( $needle, $haystack ) {
224
-        return mb_strpos( $haystack, $needle ) !== false;
223
+    public static function contains($needle, $haystack) {
224
+        return mb_strpos($haystack, $needle) !== false;
225 225
     }
226 226
 
227 227
     /**
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
      *
230 230
      * @return string
231 231
      */
232
-    public static function htmlentities( $string ) {
233
-        return htmlentities( $string, ENT_NOQUOTES );
232
+    public static function htmlentities($string) {
233
+        return htmlentities($string, ENT_NOQUOTES);
234 234
     }
235 235
 
236 236
     /**
@@ -239,15 +239,15 @@  discard block
 block discarded – undo
239 239
      *
240 240
      * @return string
241 241
      */
242
-    public static function htmlspecialchars_decode( $string, $onlyEscapedEntities = false ) {
243
-        if ( false === $onlyEscapedEntities ) {
244
-            return htmlspecialchars_decode( $string, ENT_NOQUOTES );
242
+    public static function htmlspecialchars_decode($string, $onlyEscapedEntities = false) {
243
+        if (false === $onlyEscapedEntities) {
244
+            return htmlspecialchars_decode($string, ENT_NOQUOTES);
245 245
         }
246 246
 
247
-        return preg_replace_callback( self::$htmlEntityRegex,
248
-                function ( $match ) {
249
-                    return self::htmlspecialchars_decode( $match[ 0 ] );
250
-                }, $string );
247
+        return preg_replace_callback(self::$htmlEntityRegex,
248
+                function($match) {
249
+                    return self::htmlspecialchars_decode($match[0]);
250
+                }, $string);
251 251
     }
252 252
 
253 253
     /**
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
      *
263 263
      * @return bool
264 264
      */
265
-    public static function isADoubleEscapedEntity( $str ) {
266
-        return preg_match( self::$htmlEntityRegex, $str ) != 0;
265
+    public static function isADoubleEscapedEntity($str) {
266
+        return preg_match(self::$htmlEntityRegex, $str) != 0;
267 267
     }
268 268
 
269 269
     /**
@@ -271,8 +271,8 @@  discard block
 block discarded – undo
271 271
      *
272 272
      * @return bool
273 273
      */
274
-    public static function isAnEscapedHTML( $str ) {
275
-        return preg_match( '#/[a-z]*&gt;#i', $str ) != 0;
274
+    public static function isAnEscapedHTML($str) {
275
+        return preg_match('#/[a-z]*&gt;#i', $str) != 0;
276 276
     }
277 277
 
278 278
     /**
@@ -280,8 +280,8 @@  discard block
 block discarded – undo
280 280
      *
281 281
      * @return bool
282 282
      */
283
-    public static function isAValidUuid( $uuid ) {
284
-        return preg_match( '/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid ) === 1;
283
+    public static function isAValidUuid($uuid) {
284
+        return preg_match('/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid) === 1;
285 285
     }
286 286
 
287 287
     /**
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
      *
291 291
      * @return array|false|string[]
292 292
      */
293
-    public static function preg_split( $pattern, $subject ) {
294
-        return preg_split( $pattern, $subject, -1, PREG_SPLIT_NO_EMPTY );
293
+    public static function preg_split($pattern, $subject) {
294
+        return preg_split($pattern, $subject, -1, PREG_SPLIT_NO_EMPTY);
295 295
     }
296 296
 
297 297
     /**
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
      *
310 310
      * @return string
311 311
      */
312
-    public static function escapeOnlyHTMLTags( $string ) {
313
-        return preg_replace( '/<(.*?)>/iu', '&lt;$1&gt;', $string );
312
+    public static function escapeOnlyHTMLTags($string) {
313
+        return preg_replace('/<(.*?)>/iu', '&lt;$1&gt;', $string);
314 314
     }
315 315
 
316 316
     /**
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
      *
321 321
      * @return string
322 322
      */
323
-    public static function lastChar( $string ) {
324
-        return mb_substr( $string, -1 );
323
+    public static function lastChar($string) {
324
+        return mb_substr($string, -1);
325 325
     }
326 326
 
327 327
     /**
@@ -329,8 +329,8 @@  discard block
 block discarded – undo
329 329
      *
330 330
      * @return int
331 331
      */
332
-    public static function getTheNumberOfTrailingSpaces( $segment ) {
333
-        return mb_strlen( $segment ) - mb_strlen( rtrim( $segment, ' ' ) );
332
+    public static function getTheNumberOfTrailingSpaces($segment) {
333
+        return mb_strlen($segment) - mb_strlen(rtrim($segment, ' '));
334 334
     }
335 335
 
336 336
     /**
@@ -340,15 +340,15 @@  discard block
 block discarded – undo
340 340
      *
341 341
      * @return bool
342 342
      */
343
-    public static function isHtmlString( $string ) {
344
-        $string = stripslashes( $string );
343
+    public static function isHtmlString($string) {
344
+        $string = stripslashes($string);
345 345
 
346
-        if ( $string === '<>' ) {
346
+        if ($string === '<>') {
347 347
             return false;
348 348
         }
349 349
 
350
-        preg_match( "#</?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>#", $string, $matches );
350
+        preg_match("#</?[a-zA-Z1-6-]+((\s+[a-zA-Z1-6-]+(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)/?>#", $string, $matches);
351 351
 
352
-        return count( $matches ) !== 0;
352
+        return count($matches) !== 0;
353 353
     }
354 354
 }
Please login to merge, or discard this patch.
src/XliffParser.php 1 patch
Spacing   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
      *
31 31
      * @param LoggerInterface $logger
32 32
      */
33
-    public function __construct( LoggerInterface $logger = null ) {
33
+    public function __construct(LoggerInterface $logger = null) {
34 34
         $this->logger = $logger;
35 35
     }
36 36
 
@@ -45,11 +45,11 @@  discard block
 block discarded – undo
45 45
      * @param bool                                $setSourceInTarget
46 46
      * @param XliffReplacerCallbackInterface|null $callback
47 47
      */
48
-    public function replaceTranslation( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null ) {
48
+    public function replaceTranslation($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null) {
49 49
         try {
50
-            $parser = XliffReplacerFactory::getInstance( $originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback );
50
+            $parser = XliffReplacerFactory::getInstance($originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback);
51 51
             $parser->replaceTranslation();
52
-        } catch ( Exception $exception ) {
52
+        } catch (Exception $exception) {
53 53
             // do nothing
54 54
         }
55 55
     }
@@ -67,26 +67,26 @@  discard block
 block discarded – undo
67 67
      * @throws InvalidXmlException
68 68
      * @throws XmlParsingException
69 69
      */
70
-    public function xliffToArray( $xliffContent, $collapseEmptyTags = false ) {
70
+    public function xliffToArray($xliffContent, $collapseEmptyTags = false) {
71 71
         $xliff        = [];
72
-        $xliffContent = self::forceUft8Encoding( $xliffContent, $xliff );
73
-        $xliffVersion = XliffVersionDetector::detect( $xliffContent );
74
-        $info         = XliffProprietaryDetect::getInfoFromXliffContent( $xliffContent );
72
+        $xliffContent = self::forceUft8Encoding($xliffContent, $xliff);
73
+        $xliffVersion = XliffVersionDetector::detect($xliffContent);
74
+        $info         = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent);
75 75
 
76
-        if ( $xliffVersion === 1 ) {
77
-            $xliffContent = self::removeInternalFileTagFromContent( $xliffContent, $xliff );
76
+        if ($xliffVersion === 1) {
77
+            $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff);
78 78
         }
79 79
 
80
-        if ( $xliffVersion === 2 ) {
81
-            $xliffContent = self::escapeDataInOriginalMap( $xliffContent );
80
+        if ($xliffVersion === 2) {
81
+            $xliffContent = self::escapeDataInOriginalMap($xliffContent);
82 82
         }
83 83
 
84
-        if ( $collapseEmptyTags === false ) {
85
-            $xliffContent = self::insertPlaceholderInEmptyTags( $xliffContent );
84
+        if ($collapseEmptyTags === false) {
85
+            $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent);
86 86
         }
87 87
 
88
-        $xliffProprietary = isset( $info[ 'proprietary_short_name' ] ) ? $info[ 'proprietary_short_name' ] : null;
89
-        $parser           = XliffParserFactory::getInstance( $xliffVersion, $xliffProprietary, $this->logger );
88
+        $xliffProprietary = isset($info['proprietary_short_name']) ? $info['proprietary_short_name'] : null;
89
+        $parser           = XliffParserFactory::getInstance($xliffVersion, $xliffProprietary, $this->logger);
90 90
 
91 91
         $dom = XmlDomLoader::load(
92 92
                 $xliffContent,
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
                 )
98 98
         );
99 99
 
100
-        return $parser->parse( $dom, $xliff );
100
+        return $parser->parse($dom, $xliff);
101 101
     }
102 102
 
103 103
     /**
@@ -109,12 +109,12 @@  discard block
 block discarded – undo
109 109
      *
110 110
      * @return string
111 111
      */
112
-    private static function forceUft8Encoding( $xliffContent, &$xliff ) {
113
-        $enc = mb_detect_encoding( $xliffContent );
112
+    private static function forceUft8Encoding($xliffContent, &$xliff) {
113
+        $enc = mb_detect_encoding($xliffContent);
114 114
 
115
-        if ( $enc !== 'UTF-8' ) {
116
-            $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only";
117
-            $s                            = iconv( $enc, 'UTF-8', $xliffContent );
115
+        if ($enc !== 'UTF-8') {
116
+            $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only";
117
+            $s                            = iconv($enc, 'UTF-8', $xliffContent);
118 118
             $xliffContent                 = $s !== false ? $s : "";
119 119
         }
120 120
 
@@ -131,24 +131,24 @@  discard block
 block discarded – undo
131 131
      *
132 132
      * @return mixed|string
133 133
      */
134
-    private static function removeInternalFileTagFromContent( $xliffContent, &$xliff ) {
134
+    private static function removeInternalFileTagFromContent($xliffContent, &$xliff) {
135 135
         $index = 1;
136
-        $a     = Strings::preg_split( '|<internal-file[\s>]|i', $xliffContent );
136
+        $a     = Strings::preg_split('|<internal-file[\s>]|i', $xliffContent);
137 137
 
138 138
         // no match, return original string
139
-        if ( count( $a ) === 1 ) {
140
-            return $a[ 0 ];
139
+        if (count($a) === 1) {
140
+            return $a[0];
141 141
         }
142 142
 
143
-        $b                                           = Strings::preg_split( '|</internal-file>|i', $a[ 1 ] );
144
-        $strippedContent                             = $a[ 0 ] . $b[ 1 ];
145
-        $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $b[ 0 ] );
143
+        $b                                           = Strings::preg_split('|</internal-file>|i', $a[1]);
144
+        $strippedContent                             = $a[0] . $b[1];
145
+        $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]);
146 146
         $index++;
147 147
 
148
-        if ( isset( $a[ 2 ] ) ) {
149
-            $c                                           = Strings::preg_split( '|</internal-file[\s>]|i', $a[ 2 ] );
150
-            $strippedContent                             .= $c[ 1 ];
151
-            $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $c[ 0 ] );
148
+        if (isset($a[2])) {
149
+            $c                                           = Strings::preg_split('|</internal-file[\s>]|i', $a[2]);
150
+            $strippedContent .= $c[1];
151
+            $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]);
152 152
         }
153 153
 
154 154
         return $strippedContent;
@@ -159,10 +159,10 @@  discard block
 block discarded – undo
159 159
      *
160 160
      * @return array
161 161
      */
162
-    private static function extractBase64( $base64 ) {
162
+    private static function extractBase64($base64) {
163 163
         return [
164 164
                 'form-type' => 'base64',
165
-                'base64'    => trim( str_replace( 'form="base64">', '', $base64 ) ),
165
+                'base64'    => trim(str_replace('form="base64">', '', $base64)),
166 166
         ];
167 167
     }
168 168
 
@@ -182,9 +182,9 @@  discard block
 block discarded – undo
182 182
      *
183 183
      * @return string
184 184
      */
185
-    private static function escapeDataInOriginalMap( $xliffContent ) {
186
-        $xliffContent = preg_replace_callback( '|<data(.*?)>(.*?)</data>|iU', [ XliffParser::class, 'replaceSpace' ], $xliffContent );
187
-        $xliffContent = preg_replace_callback( '|<data(.*?)>(.*?)</data>|iU', [ XliffParser::class, 'replaceXliffTags' ], $xliffContent );
185
+    private static function escapeDataInOriginalMap($xliffContent) {
186
+        $xliffContent = preg_replace_callback('|<data(.*?)>(.*?)</data>|iU', [XliffParser::class, 'replaceSpace'], $xliffContent);
187
+        $xliffContent = preg_replace_callback('|<data(.*?)>(.*?)</data>|iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent);
188 188
 
189 189
         return $xliffContent;
190 190
     }
@@ -203,15 +203,15 @@  discard block
 block discarded – undo
203 203
      *
204 204
      * @return string
205 205
      */
206
-    private static function insertPlaceholderInEmptyTags( $xliffContent ) {
207
-        preg_match_all( '|<([a-zA-Z0-9._-]+)[^>]*></\1>|m', $xliffContent, $emptyTagMatches );
206
+    private static function insertPlaceholderInEmptyTags($xliffContent) {
207
+        preg_match_all('|<([a-zA-Z0-9._-]+)[^>]*></\1>|m', $xliffContent, $emptyTagMatches);
208 208
 
209
-        if ( !empty( $emptyTagMatches[ 0 ] ) ) {
210
-            foreach ( $emptyTagMatches[ 0 ] as $index => $emptyTagMatch ) {
211
-                $matchedTag   = $emptyTagMatches[ 1 ][ $index ];
209
+        if (!empty($emptyTagMatches[0])) {
210
+            foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) {
211
+                $matchedTag   = $emptyTagMatches[1][$index];
212 212
                 $subst        = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>';
213
-                $replacedTag  = str_replace( '</' . $matchedTag . '>', $subst, $emptyTagMatch );
214
-                $xliffContent = str_replace( $emptyTagMatch, $replacedTag, $xliffContent );
213
+                $replacedTag  = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch);
214
+                $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent);
215 215
             }
216 216
         }
217 217
 
@@ -225,12 +225,12 @@  discard block
 block discarded – undo
225 225
      *
226 226
      * @return string
227 227
      */
228
-    private static function replaceSpace( $matches ) {
229
-        $content = str_replace( ' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[ 2 ] );
230
-        $content = str_replace( '\n', Placeholder::NEW_LINE_PLACEHOLDER, $content );
231
-        $content = str_replace( '\t', Placeholder::TAB_PLACEHOLDER, $content );
228
+    private static function replaceSpace($matches) {
229
+        $content = str_replace(' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[2]);
230
+        $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content);
231
+        $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content);
232 232
 
233
-        return '<data' . $matches[ 1 ] . '>' . $content . '</data>';
233
+        return '<data' . $matches[1] . '>' . $content . '</data>';
234 234
     }
235 235
 
236 236
     /**
@@ -238,15 +238,15 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @return string
240 240
      */
241
-    private static function replaceXliffTags( $matches ) {
241
+    private static function replaceXliffTags($matches) {
242 242
         $xliffTags = XliffTags::$tags;
243
-        $content   = $matches[ 2 ];
243
+        $content   = $matches[2];
244 244
 
245
-        foreach ( $xliffTags as $xliffTag ) {
246
-            $content = preg_replace( '|&lt;(' . $xliffTag . '.*?)&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content );
247
-            $content = preg_replace( '|&lt;(/' . $xliffTag . ')&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content );
245
+        foreach ($xliffTags as $xliffTag) {
246
+            $content = preg_replace('|&lt;(' . $xliffTag . '.*?)&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content);
247
+            $content = preg_replace('|&lt;(/' . $xliffTag . ')&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content);
248 248
         }
249 249
 
250
-        return '<data' . $matches[ 1 ] . '>' . $content . '</data>';
250
+        return '<data' . $matches[1] . '>' . $content . '</data>';
251 251
     }
252 252
 }
Please login to merge, or discard this patch.
src/XliffParser/XliffParserV1.php 1 patch
Spacing   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -16,33 +16,33 @@  discard block
 block discarded – undo
16 16
      * @inheritDoc
17 17
      * @throws Exception
18 18
      */
19
-    public function parse( DOMDocument $dom, $output = [] ) {
19
+    public function parse(DOMDocument $dom, $output = []) {
20 20
         $i = 1;
21 21
         /** @var DOMElement $file */
22
-        foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
22
+        foreach ($dom->getElementsByTagName('file') as $file) {
23 23
 
24 24
             // metadata
25
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $file );
25
+            $output['files'][$i]['attr'] = $this->extractMetadata($file);
26 26
 
27 27
             // reference
28
-            if ( !empty( $this->extractReference( $file ) ) ) {
29
-                $output[ 'files' ][ $i ][ 'reference' ] = $this->extractReference( $file );
28
+            if (!empty($this->extractReference($file))) {
29
+                $output['files'][$i]['reference'] = $this->extractReference($file);
30 30
             }
31 31
 
32 32
             // trans-units
33 33
             $transUnitIdArrayForUniquenessCheck = [];
34 34
             $j                                  = 1;
35
-            foreach ( $file->childNodes as $body ) {
36
-                if ( $body->nodeName === 'body' ) {
37
-                    foreach ( $body->childNodes as $childNode ) {
38
-                        $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j );
35
+            foreach ($file->childNodes as $body) {
36
+                if ($body->nodeName === 'body') {
37
+                    foreach ($body->childNodes as $childNode) {
38
+                        $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j);
39 39
                     }
40 40
 
41 41
                     // trans-unit re-count check
42
-                    $totalTransUnitsId  = count( $transUnitIdArrayForUniquenessCheck );
43
-                    $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) );
44
-                    if ( $totalTransUnitsId != $transUnitsUniqueId ) {
45
-                        throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 );
42
+                    $totalTransUnitsId  = count($transUnitIdArrayForUniquenessCheck);
43
+                    $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck));
44
+                    if ($totalTransUnitsId != $transUnitsUniqueId) {
45
+                        throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400);
46 46
                     }
47 47
 
48 48
                     $i++;
@@ -58,50 +58,50 @@  discard block
 block discarded – undo
58 58
      *
59 59
      * @return array
60 60
      */
61
-    private function extractMetadata( DOMElement $file ) {
61
+    private function extractMetadata(DOMElement $file) {
62 62
         $metadata   = [];
63 63
         $customAttr = [];
64 64
 
65 65
         /** @var DOMAttr $attribute */
66
-        foreach ( $file->attributes as $attribute ) {
67
-            switch ( $attribute->localName ) {
66
+        foreach ($file->attributes as $attribute) {
67
+            switch ($attribute->localName) {
68 68
                 // original
69 69
                 case 'original':
70
-                    $metadata[ 'original' ] = $attribute->value;
70
+                    $metadata['original'] = $attribute->value;
71 71
                     break;
72 72
 
73 73
                 // source-language
74 74
                 case 'source-language':
75
-                    $metadata[ 'source-language' ] = $attribute->value;
75
+                    $metadata['source-language'] = $attribute->value;
76 76
                     break;
77 77
 
78 78
                 // data-type
79 79
                 case 'datatype':
80
-                    $metadata[ 'data-type' ] = $attribute->value;
80
+                    $metadata['data-type'] = $attribute->value;
81 81
                     break;
82 82
 
83 83
                 // target-language
84 84
                 case 'target-language':
85
-                    $metadata[ 'target-language' ] = $attribute->value;
85
+                    $metadata['target-language'] = $attribute->value;
86 86
                     break;
87 87
             }
88 88
 
89 89
             // Custom MateCat x-Attribute
90
-            preg_match( '|x-(.*?)|si', $attribute->localName, $temp );
91
-            if ( isset( $temp[ 1 ] ) ) {
92
-                $customAttr[ $attribute->localName ] = $attribute->value;
90
+            preg_match('|x-(.*?)|si', $attribute->localName, $temp);
91
+            if (isset($temp[1])) {
92
+                $customAttr[$attribute->localName] = $attribute->value;
93 93
             }
94
-            unset( $temp );
94
+            unset($temp);
95 95
 
96 96
             // Custom MateCat namespace Attribute mtc:
97
-            preg_match( '|mtc:(.*?)|si', $attribute->nodeName, $temp );
98
-            if ( isset( $temp[ 1 ] ) ) {
99
-                $customAttr[ $attribute->nodeName ] = $attribute->value;
97
+            preg_match('|mtc:(.*?)|si', $attribute->nodeName, $temp);
98
+            if (isset($temp[1])) {
99
+                $customAttr[$attribute->nodeName] = $attribute->value;
100 100
             }
101
-            unset( $temp );
101
+            unset($temp);
102 102
 
103
-            if ( !empty( $customAttr ) ) {
104
-                $metadata[ 'custom' ] = $customAttr;
103
+            if (!empty($customAttr)) {
104
+                $metadata['custom'] = $customAttr;
105 105
             }
106 106
         }
107 107
 
@@ -113,16 +113,16 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @return array
115 115
      */
116
-    private function extractReference( DOMElement $file ) {
116
+    private function extractReference(DOMElement $file) {
117 117
         $reference = [];
118 118
 
119 119
         $order = 0;
120
-        foreach ( $file->getElementsByTagName( 'reference' ) as $ref ) {
120
+        foreach ($file->getElementsByTagName('reference') as $ref) {
121 121
             /** @var DOMNode $childNode */
122
-            foreach ( $ref->childNodes as $childNode ) {
123
-                if ( $childNode->nodeName === 'internal-file' ) {
124
-                    $reference[ $order ][ 'form-type' ] = $childNode->attributes->getNamedItem( 'form' )->nodeValue;
125
-                    $reference[ $order ][ 'base64' ]    = trim( $childNode->nodeValue );
122
+            foreach ($ref->childNodes as $childNode) {
123
+                if ($childNode->nodeName === 'internal-file') {
124
+                    $reference[$order]['form-type'] = $childNode->attributes->getNamedItem('form')->nodeValue;
125
+                    $reference[$order]['base64']    = trim($childNode->nodeValue);
126 126
                     $order++;
127 127
                 }
128 128
             }
@@ -144,60 +144,60 @@  discard block
 block discarded – undo
144 144
      *
145 145
      * @throws Exception
146 146
      */
147
-    protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) {
147
+    protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []) {
148 148
         // metadata
149
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck );
149
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
150 150
 
151 151
         // notes
152
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $dom, $transUnit );
152
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($dom, $transUnit);
153 153
 
154 154
         // content
155 155
         /** @var DOMElement $childNode */
156
-        foreach ( $transUnit->childNodes as $childNode ) {
156
+        foreach ($transUnit->childNodes as $childNode) {
157 157
             // source
158
-            if ( $childNode->nodeName === 'source' ) {
159
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ] = $this->extractContent( $dom, $childNode );
158
+            if ($childNode->nodeName === 'source') {
159
+                $output['files'][$i]['trans-units'][$j]['source'] = $this->extractContent($dom, $childNode);
160 160
             }
161 161
 
162 162
             // seg-source
163
-            if ( $childNode->nodeName === 'seg-source' ) {
164
-                $rawSegment                                                     = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ][ 'raw-content' ];
165
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode, $rawSegment );
163
+            if ($childNode->nodeName === 'seg-source') {
164
+                $rawSegment                                                     = $output['files'][$i]['trans-units'][$j]['source']['raw-content'];
165
+                $output['files'][$i]['trans-units'][$j]['seg-source'] = $this->extractContentWithMarksAndExtTags($dom, $childNode, $rawSegment);
166 166
             }
167 167
 
168 168
             // target
169
-            if ( $childNode->nodeName === 'target' ) {
170
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ] = $this->extractContent( $dom, $childNode );
169
+            if ($childNode->nodeName === 'target') {
170
+                $output['files'][$i]['trans-units'][$j]['target'] = $this->extractContent($dom, $childNode);
171 171
 
172 172
                 // seg-target
173
-                $targetRawContent = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ][ 'raw-content' ];
174
-                $segSource        = @$output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ];
175
-                if ( isset( $targetRawContent ) && !empty( $targetRawContent ) && isset( $segSource ) && count( $segSource ) > 0 ) {
176
-                    $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $this->extractContentWithMarksAndExtTags( $dom, $childNode );
177
-                    $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ][ 0 ]['attr'] = $this->extractTagAttributes($childNode);
173
+                $targetRawContent = @$output['files'][$i]['trans-units'][$j]['target']['raw-content'];
174
+                $segSource        = @$output['files'][$i]['trans-units'][$j]['seg-source'];
175
+                if (isset($targetRawContent) && !empty($targetRawContent) && isset($segSource) && count($segSource) > 0) {
176
+                    $output['files'][$i]['trans-units'][$j]['seg-target'] = $this->extractContentWithMarksAndExtTags($dom, $childNode);
177
+                    $output['files'][$i]['trans-units'][$j]['seg-target'][0]['attr'] = $this->extractTagAttributes($childNode);
178 178
                 }
179 179
             }
180 180
 
181 181
             // locked
182
-            if ( $childNode->nodeName === 'sdl:seg' ) {
183
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'locked' ] = $this->extractLocked( $childNode );
182
+            if ($childNode->nodeName === 'sdl:seg') {
183
+                $output['files'][$i]['trans-units'][$j]['locked'] = $this->extractLocked($childNode);
184 184
             }
185 185
         }
186 186
 
187 187
         // context-group
188
-        if(!empty($contextGroups)){
189
-            foreach ($contextGroups as $contextGroup){
190
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup );
188
+        if (!empty($contextGroups)) {
189
+            foreach ($contextGroups as $contextGroup) {
190
+                $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup);
191 191
             }
192 192
         }
193 193
 
194
-        foreach ( $transUnit->getElementsByTagName( 'context-group' ) as $contextGroup ) {
195
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'context-group' ][] = $this->extractTransUnitContextGroup( $dom, $contextGroup );
194
+        foreach ($transUnit->getElementsByTagName('context-group') as $contextGroup) {
195
+            $output['files'][$i]['trans-units'][$j]['context-group'][] = $this->extractTransUnitContextGroup($dom, $contextGroup);
196 196
         }
197 197
 
198 198
         // alt-trans
199
-        foreach ( $transUnit->getElementsByTagName( 'alt-trans' ) as $altTrans ) {
200
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'alt-trans' ][] = $this->extractTransUnitAltTrans( $altTrans );
199
+        foreach ($transUnit->getElementsByTagName('alt-trans') as $altTrans) {
200
+            $output['files'][$i]['trans-units'][$j]['alt-trans'][] = $this->extractTransUnitAltTrans($altTrans);
201 201
         }
202 202
 
203 203
         $j++;
@@ -210,41 +210,41 @@  discard block
 block discarded – undo
210 210
      * @return array
211 211
      * @throws Exception
212 212
      */
213
-    private function extractTransUnitMetadata( DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck ) {
213
+    private function extractTransUnitMetadata(DOMElement $transUnit, array &$transUnitIdArrayForUniquenessCheck) {
214 214
         $metadata = [];
215 215
 
216 216
         // id MUST NOT be null
217
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
218
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
217
+        if (null === $transUnit->attributes->getNamedItem('id')) {
218
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
219 219
         }
220 220
 
221 221
         /**
222 222
          * @var DOMAttr $element
223 223
          */
224
-        foreach ( $transUnit->attributes as $element ) {
224
+        foreach ($transUnit->attributes as $element) {
225 225
 
226
-            if ( $element->nodeName === "id" ) {
226
+            if ($element->nodeName === "id") {
227 227
 
228 228
                 $id = $element->nodeValue;
229 229
 
230
-                if ( strlen( $id ) > 100 ) {
231
-                    throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
230
+                if (strlen($id) > 100) {
231
+                    throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
232 232
                 }
233 233
 
234 234
                 $transUnitIdArrayForUniquenessCheck[] = $id;
235
-                $metadata[ 'id' ]                     = $id;
235
+                $metadata['id']                     = $id;
236 236
 
237
-            } elseif ( $element->nodeName === "approved" ) {
237
+            } elseif ($element->nodeName === "approved") {
238 238
                 // approved as BOOLEAN
239 239
                 // http://docs.oasis-open.org/xliff/v1.2/os/xliff-core.html#approved
240
-                $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_VALIDATE_BOOLEAN );
241
-            } elseif ( $element->nodeName === "maxwidth" ) {
240
+                $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_VALIDATE_BOOLEAN);
241
+            } elseif ($element->nodeName === "maxwidth") {
242 242
                 // we ignore ( but we get ) the attribute size-unit="char" assuming that a restriction is everytime done by character
243 243
                 // we duplicate the info to allow Xliff V1 and V2 to work the same
244
-                $metadata[ 'sizeRestriction' ]  = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT );
245
-                $metadata[ $element->nodeName ] = filter_var( $element->nodeValue, FILTER_SANITIZE_NUMBER_INT );
244
+                $metadata['sizeRestriction']  = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT);
245
+                $metadata[$element->nodeName] = filter_var($element->nodeValue, FILTER_SANITIZE_NUMBER_INT);
246 246
             } else {
247
-                $metadata[ $element->nodeName ] = $element->nodeValue;
247
+                $metadata[$element->nodeName] = $element->nodeValue;
248 248
             }
249 249
 
250 250
         }
@@ -258,19 +258,19 @@  discard block
 block discarded – undo
258 258
      * @return array
259 259
      * @throws Exception
260 260
      */
261
-    private function extractTransUnitNotes( DOMDocument $dom, DOMElement $transUnit ) {
261
+    private function extractTransUnitNotes(DOMDocument $dom, DOMElement $transUnit) {
262 262
         $notes = [];
263
-        foreach ( $transUnit->getElementsByTagName( 'note' ) as $note ) {
263
+        foreach ($transUnit->getElementsByTagName('note') as $note) {
264 264
 
265
-            $noteValue = $this->extractTagContent( $dom, $note );
265
+            $noteValue = $this->extractTagContent($dom, $note);
266 266
 
267
-            if ( '' !== $noteValue ) {
267
+            if ('' !== $noteValue) {
268 268
 
269
-                $extractedNote = $this->JSONOrRawContentArray( $noteValue );
269
+                $extractedNote = $this->JSONOrRawContentArray($noteValue);
270 270
 
271 271
                 // extract all the attributes
272
-                foreach ( $note->attributes as $attribute ) {
273
-                    $extractedNote[ $attribute->name ] = $attribute->value;
272
+                foreach ($note->attributes as $attribute) {
273
+                    $extractedNote[$attribute->name] = $attribute->value;
274 274
                 }
275 275
 
276 276
                 $notes[] = $extractedNote;
@@ -285,14 +285,14 @@  discard block
 block discarded – undo
285 285
      *
286 286
      * @return array
287 287
      */
288
-    private function extractTransUnitContextGroup( DOMDocument $dom, DOMElement $contextGroup ) {
288
+    private function extractTransUnitContextGroup(DOMDocument $dom, DOMElement $contextGroup) {
289 289
         $cg           = [];
290
-        $cg[ 'attr' ] = $this->extractTagAttributes( $contextGroup );
290
+        $cg['attr'] = $this->extractTagAttributes($contextGroup);
291 291
 
292 292
         /** @var DOMNode $context */
293
-        foreach ( $contextGroup->childNodes as $context ) {
294
-            if ( $context->nodeName === 'context' ) {
295
-                $cg[ 'contexts' ][] = $this->extractContent( $dom, $context );
293
+        foreach ($contextGroup->childNodes as $context) {
294
+            if ($context->nodeName === 'context') {
295
+                $cg['contexts'][] = $this->extractContent($dom, $context);
296 296
             }
297 297
         }
298 298
 
@@ -304,16 +304,16 @@  discard block
 block discarded – undo
304 304
      *
305 305
      * @return array
306 306
      */
307
-    private function extractTransUnitAltTrans( DOMElement $altTrans ) {
307
+    private function extractTransUnitAltTrans(DOMElement $altTrans) {
308 308
         $at           = [];
309
-        $at[ 'attr' ] = $this->extractTagAttributes( $altTrans );
309
+        $at['attr'] = $this->extractTagAttributes($altTrans);
310 310
 
311
-        if ( $altTrans->getElementsByTagName( 'source' )->length > 0 ) {
312
-            $at[ 'source' ] = $altTrans->getElementsByTagName( 'source' )->item( 0 )->nodeValue;
311
+        if ($altTrans->getElementsByTagName('source')->length > 0) {
312
+            $at['source'] = $altTrans->getElementsByTagName('source')->item(0)->nodeValue;
313 313
         }
314 314
 
315
-        if ( $altTrans->getElementsByTagName( 'target' ) ) {
316
-            $at[ 'target' ] = $altTrans->getElementsByTagName( 'target' )->item( 0 )->nodeValue;
315
+        if ($altTrans->getElementsByTagName('target')) {
316
+            $at['target'] = $altTrans->getElementsByTagName('target')->item(0)->nodeValue;
317 317
         }
318 318
 
319 319
         return $at;
@@ -324,7 +324,7 @@  discard block
 block discarded – undo
324 324
      *
325 325
      * @return bool
326 326
      */
327
-    private function extractLocked( DOMElement $locked ) {
328
-        return null !== $locked->getAttribute( 'locked' );
327
+    private function extractLocked(DOMElement $locked) {
328
+        return null !== $locked->getAttribute('locked');
329 329
     }
330 330
 }
Please login to merge, or discard this patch.
src/XliffParser/XliffParserV2.php 1 patch
Spacing   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -15,30 +15,30 @@  discard block
 block discarded – undo
15 15
      * @inheritDoc
16 16
      * @throws \Exception
17 17
      */
18
-    public function parse( DOMDocument $dom, $output = [] ) {
18
+    public function parse(DOMDocument $dom, $output = []) {
19 19
         $i = 1;
20 20
         /** @var DOMElement $file */
21
-        foreach ( $dom->getElementsByTagName( 'file' ) as $file ) {
21
+        foreach ($dom->getElementsByTagName('file') as $file) {
22 22
 
23 23
             // metadata
24
-            $output[ 'files' ][ $i ][ 'attr' ] = $this->extractMetadata( $dom );
24
+            $output['files'][$i]['attr'] = $this->extractMetadata($dom);
25 25
 
26 26
             // notes
27
-            $output[ 'files' ][ $i ][ 'notes' ] = $this->extractNotes( $file );
27
+            $output['files'][$i]['notes'] = $this->extractNotes($file);
28 28
 
29 29
             // trans-units
30 30
             $transUnitIdArrayForUniquenessCheck = [];
31 31
             $j                                  = 1;
32 32
             /** @var DOMElement $transUnit */
33
-            foreach ( $file->childNodes as $childNode ) {
34
-                $this->extractTuFromNode( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j );
33
+            foreach ($file->childNodes as $childNode) {
34
+                $this->extractTuFromNode($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j);
35 35
             }
36 36
 
37 37
             // trans-unit re-count check
38
-            $totalTransUnitsId  = count( $transUnitIdArrayForUniquenessCheck );
39
-            $transUnitsUniqueId = count( array_unique( $transUnitIdArrayForUniquenessCheck ) );
40
-            if ( $totalTransUnitsId != $transUnitsUniqueId ) {
41
-                throw new DuplicateTransUnitIdInXliff( "Invalid trans-unit id, duplicate found.", 400 );
38
+            $totalTransUnitsId  = count($transUnitIdArrayForUniquenessCheck);
39
+            $transUnitsUniqueId = count(array_unique($transUnitIdArrayForUniquenessCheck));
40
+            if ($totalTransUnitsId != $transUnitsUniqueId) {
41
+                throw new DuplicateTransUnitIdInXliff("Invalid trans-unit id, duplicate found.", 400);
42 42
             }
43 43
 
44 44
             $i++;
@@ -52,23 +52,23 @@  discard block
 block discarded – undo
52 52
      *
53 53
      * @return array
54 54
      */
55
-    private function extractMetadata( DOMDocument $dom ) {
55
+    private function extractMetadata(DOMDocument $dom) {
56 56
         $metadata = [];
57 57
 
58
-        $xliffNode = $dom->getElementsByTagName( 'xliff' )->item( 0 );
59
-        $fileNode  = $dom->getElementsByTagName( 'file' )->item( 0 );
58
+        $xliffNode = $dom->getElementsByTagName('xliff')->item(0);
59
+        $fileNode  = $dom->getElementsByTagName('file')->item(0);
60 60
 
61 61
         // original
62
-        $metadata[ 'original' ] = ( null !== $fileNode->attributes->getNamedItem( 'original' ) ) ? $fileNode->attributes->getNamedItem( 'original' )->nodeValue : 'no-name';
62
+        $metadata['original'] = (null !== $fileNode->attributes->getNamedItem('original')) ? $fileNode->attributes->getNamedItem('original')->nodeValue : 'no-name';
63 63
 
64 64
         // source-language
65
-        $metadata[ 'source-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'srcLang' ) ) ? $xliffNode->attributes->getNamedItem( 'srcLang' )->nodeValue : 'en-US';
65
+        $metadata['source-language'] = (null !== $xliffNode->attributes->getNamedItem('srcLang')) ? $xliffNode->attributes->getNamedItem('srcLang')->nodeValue : 'en-US';
66 66
 
67 67
         // datatype
68 68
         // @TODO to be implemented
69 69
 
70 70
         // target-language
71
-        $metadata[ 'target-language' ] = ( null !== $xliffNode->attributes->getNamedItem( 'trgLang' ) ) ? $xliffNode->attributes->getNamedItem( 'trgLang' )->nodeValue : 'en-US';
71
+        $metadata['target-language'] = (null !== $xliffNode->attributes->getNamedItem('trgLang')) ? $xliffNode->attributes->getNamedItem('trgLang')->nodeValue : 'en-US';
72 72
 
73 73
         // custom MateCat x-attribute
74 74
         // @TODO to be implemented
@@ -82,16 +82,16 @@  discard block
 block discarded – undo
82 82
      * @return array
83 83
      * @throws \Exception
84 84
      */
85
-    private function extractNotes( DOMElement $file ) {
85
+    private function extractNotes(DOMElement $file) {
86 86
         $notes = [];
87 87
 
88 88
         // loop <notes> to get nested <note> tag
89
-        foreach ( $file->childNodes as $childNode ) {
90
-            if ( $childNode->nodeName === 'notes' ) {
91
-                foreach ( $childNode->childNodes as $note ) {
92
-                    $noteValue = trim( $note->nodeValue );
93
-                    if ( '' !== $noteValue ) {
94
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
89
+        foreach ($file->childNodes as $childNode) {
90
+            if ($childNode->nodeName === 'notes') {
91
+                foreach ($childNode->childNodes as $note) {
92
+                    $noteValue = trim($note->nodeValue);
93
+                    if ('' !== $noteValue) {
94
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
95 95
                     }
96 96
                 }
97 97
             }
@@ -113,32 +113,32 @@  discard block
 block discarded – undo
113 113
      *
114 114
      * @throws \Exception
115 115
      */
116
-    protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] ) {
116
+    protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []) {
117 117
         // metadata
118
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ] = $this->extractTransUnitMetadata( $transUnit, $transUnitIdArrayForUniquenessCheck );
118
+        $output['files'][$i]['trans-units'][$j]['attr'] = $this->extractTransUnitMetadata($transUnit, $transUnitIdArrayForUniquenessCheck);
119 119
 
120 120
         // notes
121 121
         // merge <notes> with key and key-note contained in metadata <mda:metaGroup>
122
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] = $this->extractTransUnitNotes( $transUnit );
122
+        $output['files'][$i]['trans-units'][$j]['notes'] = $this->extractTransUnitNotes($transUnit);
123 123
 
124 124
         // uuid
125
-        foreach ( $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'notes' ] as $note ) {
126
-            if ( isset( $note[ 'raw-content' ] ) && Strings::isAValidUuid( $note[ 'raw-content' ] ) ) {
127
-                $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ][ 'uuid' ] = $note[ 'raw-content' ];
125
+        foreach ($output['files'][$i]['trans-units'][$j]['notes'] as $note) {
126
+            if (isset($note['raw-content']) && Strings::isAValidUuid($note['raw-content'])) {
127
+                $output['files'][$i]['trans-units'][$j]['attr']['uuid'] = $note['raw-content'];
128 128
             }
129 129
         }
130 130
 
131 131
         // original-data (exclusive for V2)
132 132
         // http://docs.oasis-open.org/xliff/xliff-core/v2.0/xliff-core-v2.0.html#originaldata
133
-        $originalData = $this->extractTransUnitOriginalData( $transUnit );
134
-        if ( !empty( $originalData ) ) {
135
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'original-data' ] = $originalData;
133
+        $originalData = $this->extractTransUnitOriginalData($transUnit);
134
+        if (!empty($originalData)) {
135
+            $output['files'][$i]['trans-units'][$j]['original-data'] = $originalData;
136 136
         }
137 137
 
138 138
         // additionalTagData (exclusive for V2)
139
-        $additionalTagData = $this->extractTransUnitAdditionalTagData( $transUnit );
140
-        if ( !empty( $additionalTagData ) ) {
141
-            $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'additional-tag-data' ] = $additionalTagData;
139
+        $additionalTagData = $this->extractTransUnitAdditionalTagData($transUnit);
140
+        if (!empty($additionalTagData)) {
141
+            $output['files'][$i]['trans-units'][$j]['additional-tag-data'] = $additionalTagData;
142 142
         }
143 143
 
144 144
         // content
@@ -158,54 +158,54 @@  discard block
 block discarded – undo
158 158
 
159 159
         /** @var DOMElement $segment */
160 160
         $c = 0;
161
-        foreach ( $transUnit->childNodes as $segment ) {
162
-            if ( $segment->nodeName === 'segment' ) {
161
+        foreach ($transUnit->childNodes as $segment) {
162
+            if ($segment->nodeName === 'segment') {
163 163
 
164 164
                 // check segment id consistency
165
-                $attr = $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'attr' ];
166
-                $this->checkSegmentIdConsistency( $segment, $attr );
165
+                $attr = $output['files'][$i]['trans-units'][$j]['attr'];
166
+                $this->checkSegmentIdConsistency($segment, $attr);
167 167
 
168 168
                 // loop <segment> to get nested <source> and <target> tag
169
-                foreach ( $segment->childNodes as $childNode ) {
170
-                    if ( $childNode->nodeName === 'source' ) {
171
-                        $extractedSource               = $this->extractContent( $dom, $childNode );
172
-                        $source[ 'raw-content' ][ $c ] = $extractedSource[ 'raw-content' ];
169
+                foreach ($segment->childNodes as $childNode) {
170
+                    if ($childNode->nodeName === 'source') {
171
+                        $extractedSource               = $this->extractContent($dom, $childNode);
172
+                        $source['raw-content'][$c] = $extractedSource['raw-content'];
173 173
 
174
-                        if ( !empty( $extractedSource[ 'attr' ] ) ) {
175
-                            $source[ 'attr' ][ $c ] = $extractedSource[ 'attr' ];
174
+                        if (!empty($extractedSource['attr'])) {
175
+                            $source['attr'][$c] = $extractedSource['attr'];
176 176
                         }
177 177
 
178 178
                         // append value to 'seg-source'
179
-                        if ( $this->stringContainsMarks( $extractedSource[ 'raw-content' ] ) ) {
180
-                            $segSource = $this->extractContentWithMarksAndExtTags( $dom, $childNode );
179
+                        if ($this->stringContainsMarks($extractedSource['raw-content'])) {
180
+                            $segSource = $this->extractContentWithMarksAndExtTags($dom, $childNode);
181 181
                         } else {
182 182
                             $segSource[] = [
183
-                                    'attr'             => $this->extractTagAttributes( $segment),
184
-                                    'mid'              => count( $segSource ) > 0 ? count( $segSource ) : 0,
183
+                                    'attr'             => $this->extractTagAttributes($segment),
184
+                                    'mid'              => count($segSource) > 0 ? count($segSource) : 0,
185 185
                                     'ext-prec-tags'    => '',
186
-                                    'raw-content'      => $extractedSource[ 'raw-content' ],
186
+                                    'raw-content'      => $extractedSource['raw-content'],
187 187
                                     'ext-succ-tags'    => '',
188 188
                             ];
189 189
                         }
190 190
                     }
191 191
 
192
-                    if ( $childNode->nodeName === 'target' ) {
193
-                        $extractedTarget               = $this->extractContent( $dom, $childNode );
194
-                        $target[ 'raw-content' ][ $c ] = $extractedTarget[ 'raw-content' ];
192
+                    if ($childNode->nodeName === 'target') {
193
+                        $extractedTarget               = $this->extractContent($dom, $childNode);
194
+                        $target['raw-content'][$c] = $extractedTarget['raw-content'];
195 195
 
196
-                        if ( !empty( $extractedTarget[ 'attr' ] ) ) {
197
-                            $target[ 'attr' ][ $c ] = $extractedTarget[ 'attr' ];
196
+                        if (!empty($extractedTarget['attr'])) {
197
+                            $target['attr'][$c] = $extractedTarget['attr'];
198 198
                         }
199 199
 
200 200
                         // append value to 'seg-target'
201
-                        if ( $this->stringContainsMarks( $extractedTarget[ 'raw-content' ] ) ) {
202
-                            $segTarget = $this->extractContentWithMarksAndExtTags( $dom, $childNode );
201
+                        if ($this->stringContainsMarks($extractedTarget['raw-content'])) {
202
+                            $segTarget = $this->extractContentWithMarksAndExtTags($dom, $childNode);
203 203
                         } else {
204 204
                             $segTarget[] = [
205
-                                    'attr'             => $this->extractTagAttributes( $segment),
206
-                                    'mid'              => count( $segTarget ) > 0 ? count( $segTarget ) : 0,
205
+                                    'attr'             => $this->extractTagAttributes($segment),
206
+                                    'mid'              => count($segTarget) > 0 ? count($segTarget) : 0,
207 207
                                     'ext-prec-tags'    => '',
208
-                                    'raw-content'      => $extractedTarget[ 'raw-content' ],
208
+                                    'raw-content'      => $extractedTarget['raw-content'],
209 209
                                     'ext-succ-tags'    => '',
210 210
                             ];
211 211
                         }
@@ -216,10 +216,10 @@  discard block
 block discarded – undo
216 216
             }
217 217
         }
218 218
 
219
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'source' ]     = $source;
220
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'target' ]     = $target;
221
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-source' ] = $segSource;
222
-        $output[ 'files' ][ $i ][ 'trans-units' ][ $j ][ 'seg-target' ] = $segTarget;
219
+        $output['files'][$i]['trans-units'][$j]['source']     = $source;
220
+        $output['files'][$i]['trans-units'][$j]['target']     = $target;
221
+        $output['files'][$i]['trans-units'][$j]['seg-source'] = $segSource;
222
+        $output['files'][$i]['trans-units'][$j]['seg-target'] = $segTarget;
223 223
 
224 224
         $j++;
225 225
     }
@@ -230,41 +230,41 @@  discard block
 block discarded – undo
230 230
      *
231 231
      * @return array
232 232
      */
233
-    private function extractTransUnitMetadata( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck ) {
233
+    private function extractTransUnitMetadata(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck) {
234 234
         $metadata = [];
235 235
 
236 236
         // id
237
-        if ( null === $transUnit->attributes->getNamedItem( 'id' ) ) {
238
-            throw new NotFoundIdInTransUnit( 'Invalid trans-unit id found. EMPTY value', 400 );
237
+        if (null === $transUnit->attributes->getNamedItem('id')) {
238
+            throw new NotFoundIdInTransUnit('Invalid trans-unit id found. EMPTY value', 400);
239 239
         }
240 240
 
241
-        $id = $transUnit->attributes->getNamedItem( 'id' )->nodeValue;
241
+        $id = $transUnit->attributes->getNamedItem('id')->nodeValue;
242 242
 
243
-        if ( strlen( $id ) > 100 ) {
244
-            throw new SegmentIdTooLongException( 'Segment-id too long. Max 100 characters allowed', 400 );
243
+        if (strlen($id) > 100) {
244
+            throw new SegmentIdTooLongException('Segment-id too long. Max 100 characters allowed', 400);
245 245
         }
246 246
 
247 247
         $transUnitIdArrayForUniquenessCheck[] = $id;
248
-        $metadata[ 'id' ]                     = $id;
248
+        $metadata['id']                     = $id;
249 249
 
250 250
         // translate
251
-        if ( null !== $transUnit->attributes->getNamedItem( 'translate' ) ) {
252
-            $metadata[ 'translate' ] = $transUnit->attributes->getNamedItem( 'translate' )->nodeValue;
251
+        if (null !== $transUnit->attributes->getNamedItem('translate')) {
252
+            $metadata['translate'] = $transUnit->attributes->getNamedItem('translate')->nodeValue;
253 253
         }
254 254
 
255 255
         // tGroupBegin
256
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupBegin' ) ) {
257
-            $metadata[ 'tGroupBegin' ] = $transUnit->attributes->getNamedItem( 'tGroupBegin' )->nodeValue;
256
+        if (null !== $transUnit->attributes->getNamedItem('tGroupBegin')) {
257
+            $metadata['tGroupBegin'] = $transUnit->attributes->getNamedItem('tGroupBegin')->nodeValue;
258 258
         }
259 259
 
260 260
         // tGroupEnd
261
-        if ( null !== $transUnit->attributes->getNamedItem( 'tGroupEnd' ) ) {
262
-            $metadata[ 'tGroupEnd' ] = $transUnit->attributes->getNamedItem( 'tGroupEnd' )->nodeValue;
261
+        if (null !== $transUnit->attributes->getNamedItem('tGroupEnd')) {
262
+            $metadata['tGroupEnd'] = $transUnit->attributes->getNamedItem('tGroupEnd')->nodeValue;
263 263
         }
264 264
 
265 265
         // sizeRestriction
266
-        if ( null !== $transUnit->attributes->getNamedItem( 'sizeRestriction' ) && '' !== $transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue ) {
267
-            $metadata[ 'sizeRestriction' ] = (int)$transUnit->attributes->getNamedItem( 'sizeRestriction' )->nodeValue;
266
+        if (null !== $transUnit->attributes->getNamedItem('sizeRestriction') && '' !== $transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue) {
267
+            $metadata['sizeRestriction'] = (int)$transUnit->attributes->getNamedItem('sizeRestriction')->nodeValue;
268 268
         }
269 269
 
270 270
         return $metadata;
@@ -276,31 +276,31 @@  discard block
 block discarded – undo
276 276
      * @return array
277 277
      * @throws \Exception
278 278
      */
279
-    private function extractTransUnitOriginalData( DOMElement $transUnit ) {
279
+    private function extractTransUnitOriginalData(DOMElement $transUnit) {
280 280
         $originalData = [];
281 281
 
282 282
         // loop <originalData> to get nested content
283
-        foreach ( $transUnit->childNodes as $childNode ) {
284
-            if ( $childNode->nodeName === 'originalData' ) {
285
-                foreach ( $childNode->childNodes as $data ) {
286
-                    if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
287
-                        $dataId = $data->attributes->getNamedItem( 'id' )->nodeValue;
283
+        foreach ($transUnit->childNodes as $childNode) {
284
+            if ($childNode->nodeName === 'originalData') {
285
+                foreach ($childNode->childNodes as $data) {
286
+                    if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
287
+                        $dataId = $data->attributes->getNamedItem('id')->nodeValue;
288 288
 
289
-                        $dataValue = str_replace( Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue );
290
-                        $dataValue = str_replace( Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue );
291
-                        $dataValue = str_replace( Placeholder::TAB_PLACEHOLDER, '\t', $dataValue );
289
+                        $dataValue = str_replace(Placeholder::WHITE_SPACE_PLACEHOLDER, ' ', $data->nodeValue);
290
+                        $dataValue = str_replace(Placeholder::NEW_LINE_PLACEHOLDER, '\n', $dataValue);
291
+                        $dataValue = str_replace(Placeholder::TAB_PLACEHOLDER, '\t', $dataValue);
292 292
 
293
-                        if ( '' !== $dataValue ) {
293
+                        if ('' !== $dataValue) {
294 294
 
295
-                            $jsonOrRawContentArray = $this->JSONOrRawContentArray( $dataValue, false );
295
+                            $jsonOrRawContentArray = $this->JSONOrRawContentArray($dataValue, false);
296 296
 
297 297
                             // restore xliff tags
298
-                            if ( isset( $jsonOrRawContentArray[ 'json' ] ) ) {
299
-                                $jsonOrRawContentArray[ 'json' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'json' ] );
298
+                            if (isset($jsonOrRawContentArray['json'])) {
299
+                                $jsonOrRawContentArray['json'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['json']);
300 300
                             }
301 301
 
302
-                            if ( isset( $jsonOrRawContentArray[ 'raw-content' ] ) ) {
303
-                                $jsonOrRawContentArray[ 'raw-content' ] = str_replace( [ Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER ], [ '&lt;', '&gt;' ], $jsonOrRawContentArray[ 'raw-content' ] );
302
+                            if (isset($jsonOrRawContentArray['raw-content'])) {
303
+                                $jsonOrRawContentArray['raw-content'] = str_replace([Placeholder::LT_PLACEHOLDER, Placeholder::GT_PLACEHOLDER], ['&lt;', '&gt;'], $jsonOrRawContentArray['raw-content']);
304 304
                             }
305 305
 
306 306
                             $originalData[] = array_merge(
@@ -325,41 +325,41 @@  discard block
 block discarded – undo
325 325
      *
326 326
      * @return array
327 327
      */
328
-    private function extractTransUnitAdditionalTagData( DOMElement $transUnit ) {
328
+    private function extractTransUnitAdditionalTagData(DOMElement $transUnit) {
329 329
         $additionalTagData = [];
330 330
 
331 331
         // loop <originalData> to get nested content
332
-        foreach ( $transUnit->childNodes as $childNode ) {
333
-            if ( $childNode->nodeName === 'memsource:additionalTagData' ) {
334
-                foreach ( $childNode->childNodes as $data ) {
332
+        foreach ($transUnit->childNodes as $childNode) {
333
+            if ($childNode->nodeName === 'memsource:additionalTagData') {
334
+                foreach ($childNode->childNodes as $data) {
335 335
                     $dataArray = [];
336 336
 
337 337
                     // id
338
-                    if ( $data->nodeName === 'memsource:tag' ) {
339
-                        if ( null !== $data->attributes && null !== $data->attributes->getNamedItem( 'id' ) ) {
340
-                            $dataId                      = $data->attributes->getNamedItem( 'id' )->nodeValue;
341
-                            $dataArray[ 'attr' ][ 'id' ] = $dataId;
338
+                    if ($data->nodeName === 'memsource:tag') {
339
+                        if (null !== $data->attributes && null !== $data->attributes->getNamedItem('id')) {
340
+                            $dataId                      = $data->attributes->getNamedItem('id')->nodeValue;
341
+                            $dataArray['attr']['id'] = $dataId;
342 342
                         }
343 343
                     }
344 344
 
345 345
                     // in PHP 7.4 $data->childNodes is an empty DomNodeList, it is iterable with size 0
346 346
                     // PHP 5.6 check: in php 5.6 $data->childNodes can be null
347
-                    if ( $data->childNodes != null ) {
347
+                    if ($data->childNodes != null) {
348 348
 
349 349
                         // content
350
-                        foreach ( $data->childNodes as $datum ) {
351
-                            if ( $datum->nodeName === 'memsource:tagId' ) {
352
-                                $dataArray[ 'raw-content' ][ 'tagId' ] = $datum->nodeValue;
350
+                        foreach ($data->childNodes as $datum) {
351
+                            if ($datum->nodeName === 'memsource:tagId') {
352
+                                $dataArray['raw-content']['tagId'] = $datum->nodeValue;
353 353
                             }
354 354
 
355
-                            if ( $datum->nodeName === 'memsource:type' ) {
356
-                                $dataArray[ 'raw-content' ][ 'type' ] = $datum->nodeValue;
355
+                            if ($datum->nodeName === 'memsource:type') {
356
+                                $dataArray['raw-content']['type'] = $datum->nodeValue;
357 357
                             }
358 358
                         }
359 359
 
360 360
                     }
361 361
 
362
-                    if ( !empty( $dataArray ) ) {
362
+                    if (!empty($dataArray)) {
363 363
                         $additionalTagData[] = $dataArray;
364 364
                     }
365 365
                 }
@@ -375,15 +375,15 @@  discard block
 block discarded – undo
375 375
      * @param DOMElement $segment
376 376
      * @param array      $attr
377 377
      */
378
-    private function checkSegmentIdConsistency( DOMElement $segment, array $attr ) {
379
-        if ( isset( $attr[ 'tGroupBegin' ] ) && isset( $attr[ 'tGroupEnd' ] ) && $segment->attributes->getNamedItem( 'id' ) ) {
380
-            $id  = $segment->attributes->getNamedItem( 'id' )->nodeValue;
381
-            $min = (int)$attr[ 'tGroupBegin' ];
382
-            $max = (int)$attr[ 'tGroupEnd' ];
383
-
384
-            if ( false === ( ( $min <= $id ) && ( $id <= $max ) ) ) {
385
-                if ( $this->logger ) {
386
-                    $this->logger->warning( 'Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd' );
378
+    private function checkSegmentIdConsistency(DOMElement $segment, array $attr) {
379
+        if (isset($attr['tGroupBegin']) && isset($attr['tGroupEnd']) && $segment->attributes->getNamedItem('id')) {
380
+            $id  = $segment->attributes->getNamedItem('id')->nodeValue;
381
+            $min = (int)$attr['tGroupBegin'];
382
+            $max = (int)$attr['tGroupEnd'];
383
+
384
+            if (false === (($min <= $id) && ($id <= $max))) {
385
+                if ($this->logger) {
386
+                    $this->logger->warning('Segment #' . $id . ' is not included within tGroupBegin and tGroupEnd');
387 387
                 }
388 388
             }
389 389
         }
@@ -395,31 +395,31 @@  discard block
 block discarded – undo
395 395
      * @return array
396 396
      * @throws \Exception
397 397
      */
398
-    private function extractTransUnitNotes( DOMElement $transUnit ) {
398
+    private function extractTransUnitNotes(DOMElement $transUnit) {
399 399
         $notes = [];
400 400
 
401 401
         // loop <notes> to get nested <note> tag
402
-        foreach ( $transUnit->childNodes as $childNode ) {
403
-            if ( $childNode->nodeName == 'notes' ) {
404
-                foreach ( $childNode->childNodes as $note ) {
405
-                    $noteValue = trim( $note->nodeValue );
406
-                    if ( '' !== $noteValue ) {
407
-                        $notes[] = $this->JSONOrRawContentArray( $noteValue );
402
+        foreach ($transUnit->childNodes as $childNode) {
403
+            if ($childNode->nodeName == 'notes') {
404
+                foreach ($childNode->childNodes as $note) {
405
+                    $noteValue = trim($note->nodeValue);
406
+                    if ('' !== $noteValue) {
407
+                        $notes[] = $this->JSONOrRawContentArray($noteValue);
408 408
                     }
409 409
                 }
410 410
             }
411 411
 
412
-            if ( $childNode->nodeName === 'mda:metadata' ) {
413
-                foreach ( $childNode->childNodes as $metadata ) {
414
-                    if ( $metadata->nodeName === 'mda:metaGroup' ) {
415
-                        foreach ( $metadata->childNodes as $meta ) {
416
-                            if ( null !== $meta->attributes && null !== $meta->attributes->getNamedItem( 'type' ) ) {
417
-                                $type      = $meta->attributes->getNamedItem( 'type' )->nodeValue;
418
-                                $metaValue = trim( $meta->nodeValue );
412
+            if ($childNode->nodeName === 'mda:metadata') {
413
+                foreach ($childNode->childNodes as $metadata) {
414
+                    if ($metadata->nodeName === 'mda:metaGroup') {
415
+                        foreach ($metadata->childNodes as $meta) {
416
+                            if (null !== $meta->attributes && null !== $meta->attributes->getNamedItem('type')) {
417
+                                $type      = $meta->attributes->getNamedItem('type')->nodeValue;
418
+                                $metaValue = trim($meta->nodeValue);
419 419
 
420
-                                if ( '' !== $metaValue ) {
420
+                                if ('' !== $metaValue) {
421 421
                                     $notes[] = array_merge(
422
-                                            $this->JSONOrRawContentArray( $metaValue ),
422
+                                            $this->JSONOrRawContentArray($metaValue),
423 423
                                             [
424 424
                                                     'attr' => [
425 425
                                                             'type' => $type
Please login to merge, or discard this patch.
src/XliffParser/AbstractXliffParser.php 1 patch
Spacing   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
      * @param string|null          $xliffProprietary
38 38
      * @param LoggerInterface|null $logger
39 39
      */
40
-    public function __construct( $xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null ) {
40
+    public function __construct($xliffVersion, $xliffProprietary = null, LoggerInterface $logger = null) {
41 41
         $this->xliffVersion     = $xliffVersion;
42 42
         $this->logger           = $logger;
43 43
         $this->xliffProprietary = $xliffProprietary;
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
      * @return string
48 48
      */
49 49
     protected function getTuTagName() {
50
-        return ( $this->xliffVersion === 1 ) ? 'trans-unit' : 'unit';
50
+        return ($this->xliffVersion === 1) ? 'trans-unit' : 'unit';
51 51
     }
52 52
 
53 53
     /**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
      *
56 56
      * @return array
57 57
      */
58
-    abstract public function parse( DOMDocument $dom, $output = [] );
58
+    abstract public function parse(DOMDocument $dom, $output = []);
59 59
 
60 60
     /**
61 61
      * Extract trans-unit content from the current node
@@ -70,17 +70,17 @@  discard block
 block discarded – undo
70 70
      * @param int          $recursionLevel
71 71
      *
72 72
      */
73
-    protected function extractTuFromNode( DOMNode $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0 ) {
73
+    protected function extractTuFromNode(DOMNode $childNode, &$transUnitIdArrayForUniquenessCheck, DOMDocument $dom, &$output, &$i, &$j, $contextGroups = [], $recursionLevel = 0) {
74 74
 
75
-        if ( $childNode->nodeType != XML_ELEMENT_NODE ) {
75
+        if ($childNode->nodeType != XML_ELEMENT_NODE) {
76 76
             return;
77 77
         }
78 78
 
79
-        if ( $childNode->nodeName === 'group' ) {
79
+        if ($childNode->nodeName === 'group') {
80 80
 
81 81
             // add nested context-groups
82
-            foreach ( $childNode->childNodes as $nestedChildNode ) {
83
-                if ( $nestedChildNode->nodeName === 'context-group' ) {
82
+            foreach ($childNode->childNodes as $nestedChildNode) {
83
+                if ($nestedChildNode->nodeName === 'context-group') {
84 84
                     $contextGroups[] = $nestedChildNode;
85 85
                 }
86 86
             }
@@ -88,23 +88,23 @@  discard block
 block discarded – undo
88 88
             // avoid infinite recursion
89 89
             $recursionLevel++;
90 90
 
91
-            foreach ( $childNode->childNodes as $nestedChildNode ) {
91
+            foreach ($childNode->childNodes as $nestedChildNode) {
92 92
 
93 93
                 // nested groups
94
-                if ( $nestedChildNode->nodeName === 'group' ) {
94
+                if ($nestedChildNode->nodeName === 'group') {
95 95
 
96
-                    if ( $recursionLevel < self::MAX_GROUP_RECURSION_LEVEL ) {
97
-                        $this->extractTuFromNode( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel );
96
+                    if ($recursionLevel < self::MAX_GROUP_RECURSION_LEVEL) {
97
+                        $this->extractTuFromNode($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups, $recursionLevel);
98 98
                     } else {
99
-                        throw new OverflowException( "Maximum tag group nesting level of '" . self::MAX_GROUP_RECURSION_LEVEL . "' reached, aborting!" );
99
+                        throw new OverflowException("Maximum tag group nesting level of '" . self::MAX_GROUP_RECURSION_LEVEL . "' reached, aborting!");
100 100
                     }
101 101
 
102
-                } elseif ( $nestedChildNode->nodeName === $this->getTuTagName() ) {
103
-                    $this->extractTransUnit( $nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups );
102
+                } elseif ($nestedChildNode->nodeName === $this->getTuTagName()) {
103
+                    $this->extractTransUnit($nestedChildNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups);
104 104
                 }
105 105
             }
106
-        } elseif ( $childNode->nodeName === $this->getTuTagName() ) {
107
-            $this->extractTransUnit( $childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups );
106
+        } elseif ($childNode->nodeName === $this->getTuTagName()) {
107
+            $this->extractTransUnit($childNode, $transUnitIdArrayForUniquenessCheck, $dom, $output, $i, $j, $contextGroups);
108 108
         }
109 109
     }
110 110
 
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      *
122 122
      * @return mixed
123 123
      */
124
-    abstract protected function extractTransUnit( DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = [] );
124
+    abstract protected function extractTransUnit(DOMElement $transUnit, &$transUnitIdArrayForUniquenessCheck, $dom, &$output, &$i, &$j, $contextGroups = []);
125 125
 
126 126
     /**
127 127
      * @param DOMDocument $dom
@@ -129,10 +129,10 @@  discard block
 block discarded – undo
129 129
      *
130 130
      * @return array
131 131
      */
132
-    protected function extractContent( DOMDocument $dom, DOMNode $node ) {
132
+    protected function extractContent(DOMDocument $dom, DOMNode $node) {
133 133
         return [
134
-                'raw-content' => $this->extractTagContent( $dom, $node ),
135
-                'attr'        => $this->extractTagAttributes( $node )
134
+                'raw-content' => $this->extractTagContent($dom, $node),
135
+                'attr'        => $this->extractTagAttributes($node)
136 136
         ];
137 137
     }
138 138
 
@@ -149,12 +149,12 @@  discard block
 block discarded – undo
149 149
      *
150 150
      * @return array
151 151
      */
152
-    protected function extractTagAttributes( DOMNode $element ) {
152
+    protected function extractTagAttributes(DOMNode $element) {
153 153
         $tagAttributes = [];
154 154
 
155
-        if ( $element->hasAttributes() ) {
156
-            foreach ( $element->attributes as $attr ) {
157
-                $tagAttributes[ $attr->nodeName ] = $attr->nodeValue;
155
+        if ($element->hasAttributes()) {
156
+            foreach ($element->attributes as $attr) {
157
+                $tagAttributes[$attr->nodeName] = $attr->nodeValue;
158 158
             }
159 159
         }
160 160
 
@@ -169,17 +169,17 @@  discard block
 block discarded – undo
169 169
      *
170 170
      * @return string
171 171
      */
172
-    protected function extractTagContent( DOMDocument $dom, DOMNode $element ) {
172
+    protected function extractTagContent(DOMDocument $dom, DOMNode $element) {
173 173
         $childNodes       = $element->hasChildNodes();
174 174
         $extractedContent = '';
175 175
 
176
-        if ( !empty( $childNodes ) ) {
177
-            foreach ( $element->childNodes as $node ) {
178
-                $extractedContent .= Emoji::toEntity( Strings::fixNonWellFormedXml( $dom->saveXML( $node ) ) );
176
+        if (!empty($childNodes)) {
177
+            foreach ($element->childNodes as $node) {
178
+                $extractedContent .= Emoji::toEntity(Strings::fixNonWellFormedXml($dom->saveXML($node)));
179 179
             }
180 180
         }
181 181
 
182
-        return str_replace( Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent );
182
+        return str_replace(Placeholder::EMPTY_TAG_PLACEHOLDER, '', $extractedContent);
183 183
     }
184 184
 
185 185
     /**
@@ -190,45 +190,45 @@  discard block
 block discarded – undo
190 190
      *
191 191
      * @return array
192 192
      */
193
-    protected function extractContentWithMarksAndExtTags( DOMDocument $dom, DOMElement $childNode ) {
193
+    protected function extractContentWithMarksAndExtTags(DOMDocument $dom, DOMElement $childNode) {
194 194
         $source = [];
195 195
 
196 196
         // example:
197 197
         // <g id="1"><mrk mid="0" mtype="seg">An English string with g tags</mrk></g>
198
-        $raw = $this->extractTagContent( $dom, $childNode );
198
+        $raw = $this->extractTagContent($dom, $childNode);
199 199
 
200
-        $markers = preg_split( '#<mrk\s#si', $raw, -1 );
200
+        $markers = preg_split('#<mrk\s#si', $raw, -1);
201 201
 
202 202
         $mi = 0;
203
-        while ( isset( $markers[ $mi + 1 ] ) ) {
204
-            unset( $mid );
203
+        while (isset($markers[$mi + 1])) {
204
+            unset($mid);
205 205
 
206
-            preg_match( '|mid\s?=\s?["\'](.*?)["\']|si', $markers[ $mi + 1 ], $mid );
206
+            preg_match('|mid\s?=\s?["\'](.*?)["\']|si', $markers[$mi + 1], $mid);
207 207
 
208 208
             // if it's a Trados file the trailing spaces after </mrk> are meaningful
209 209
             // so we add them to
210 210
             $trailingSpaces = '';
211
-            if ( $this->xliffProprietary === 'trados' ) {
212
-                preg_match_all( '/<\/mrk>[\s]+/iu', $markers[ $mi + 1 ], $trailingSpacesMatches );
211
+            if ($this->xliffProprietary === 'trados') {
212
+                preg_match_all('/<\/mrk>[\s]+/iu', $markers[$mi + 1], $trailingSpacesMatches);
213 213
 
214
-                if ( isset( $trailingSpacesMatches[ 0 ] ) && count( $trailingSpacesMatches[ 0 ] ) > 0 ) {
215
-                    foreach ( $trailingSpacesMatches[ 0 ] as $match ) {
216
-                        $trailingSpaces = str_replace( '</mrk>', '', $match );
214
+                if (isset($trailingSpacesMatches[0]) && count($trailingSpacesMatches[0]) > 0) {
215
+                    foreach ($trailingSpacesMatches[0] as $match) {
216
+                        $trailingSpaces = str_replace('</mrk>', '', $match);
217 217
                     }
218 218
                 }
219 219
             }
220 220
 
221 221
             //re-build the mrk tag after the split
222
-            $originalMark = trim( '<mrk ' . $markers[ $mi + 1 ] );
222
+            $originalMark = trim('<mrk ' . $markers[$mi + 1]);
223 223
 
224
-            $mark_string  = preg_replace( '#^<mrk\s[^>]+>(.*)#', '$1', $originalMark ); // at this point we have: ---> 'Test </mrk> </g>>'
225
-            $mark_content = preg_split( '#</mrk>#si', $mark_string );
224
+            $mark_string  = preg_replace('#^<mrk\s[^>]+>(.*)#', '$1', $originalMark); // at this point we have: ---> 'Test </mrk> </g>>'
225
+            $mark_content = preg_split('#</mrk>#si', $mark_string);
226 226
 
227 227
             $sourceArray = [
228
-                    'mid'           => ( isset( $mid[ 1 ] ) ) ? $mid[ 1 ] : $mi,
229
-                    'ext-prec-tags' => ( $mi == 0 ? $markers[ 0 ] : "" ),
230
-                    'raw-content'   => ( isset( $mark_content[ 0 ] ) ) ? $mark_content[ 0 ] . $trailingSpaces : '',
231
-                    'ext-succ-tags' => ( isset( $mark_content[ 1 ] ) ) ? $mark_content[ 1 ] : '',
228
+                    'mid'           => (isset($mid[1])) ? $mid[1] : $mi,
229
+                    'ext-prec-tags' => ($mi == 0 ? $markers[0] : ""),
230
+                    'raw-content'   => (isset($mark_content[0])) ? $mark_content[0] . $trailingSpaces : '',
231
+                    'ext-succ-tags' => (isset($mark_content[1])) ? $mark_content[1] : '',
232 232
             ];
233 233
 
234 234
             $source[] = $sourceArray;
@@ -244,12 +244,12 @@  discard block
 block discarded – undo
244 244
      *
245 245
      * @return array
246 246
      */
247
-    protected function getDataRefMap( $originalData ) {
247
+    protected function getDataRefMap($originalData) {
248 248
         // dataRef map
249 249
         $dataRefMap = [];
250
-        foreach ( $originalData as $datum ) {
251
-            if ( isset( $datum[ 'attr' ][ 'id' ] ) ) {
252
-                $dataRefMap[ $datum[ 'attr' ][ 'id' ] ] = $datum[ 'raw-content' ];
250
+        foreach ($originalData as $datum) {
251
+            if (isset($datum['attr']['id'])) {
252
+                $dataRefMap[$datum['attr']['id']] = $datum['raw-content'];
253 253
             }
254 254
         }
255 255
 
@@ -261,10 +261,10 @@  discard block
 block discarded – undo
261 261
      *
262 262
      * @return bool
263 263
      */
264
-    protected function stringContainsMarks( $raw ) {
265
-        $markers = preg_split( '#<mrk\s#si', $raw, -1 );
264
+    protected function stringContainsMarks($raw) {
265
+        $markers = preg_split('#<mrk\s#si', $raw, -1);
266 266
 
267
-        return isset( $markers[ 1 ] );
267
+        return isset($markers[1]);
268 268
     }
269 269
 
270 270
     /**
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
      * @return array
275 275
      * @throws \Exception
276 276
      */
277
-    protected function JSONOrRawContentArray( $noteValue, $escapeStrings = true ) {
277
+    protected function JSONOrRawContentArray($noteValue, $escapeStrings = true) {
278 278
         //
279 279
         // convert double escaped entites
280 280
         //
@@ -284,17 +284,17 @@  discard block
 block discarded – undo
284 284
         // &amp;amp; ---> &amp;
285 285
         // &amp;apos ---> &apos;
286 286
         //
287
-        if ( Strings::isADoubleEscapedEntity( $noteValue ) ) {
288
-            $noteValue = Strings::htmlspecialchars_decode( $noteValue, true );
287
+        if (Strings::isADoubleEscapedEntity($noteValue)) {
288
+            $noteValue = Strings::htmlspecialchars_decode($noteValue, true);
289 289
         } else {
290 290
             // for non escaped entities $escapeStrings is always true for security reasons
291 291
             $escapeStrings = true;
292 292
         }
293 293
 
294
-        if ( Strings::isJSON( $noteValue ) ) {
295
-            return [ 'json' => Strings::cleanCDATA( $noteValue ) ];
294
+        if (Strings::isJSON($noteValue)) {
295
+            return ['json' => Strings::cleanCDATA($noteValue)];
296 296
         }
297 297
 
298
-        return [ 'raw-content' => Strings::fixNonWellFormedXml( $noteValue, $escapeStrings ) ];
298
+        return ['raw-content' => Strings::fixNonWellFormedXml($noteValue, $escapeStrings)];
299 299
     }
300 300
 }
Please login to merge, or discard this patch.
src/XliffReplacer/Xliff20.php 1 patch
Spacing   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -32,18 +32,18 @@  discard block
 block discarded – undo
32 32
     /**
33 33
      * @inheritDoc
34 34
      */
35
-    protected function tagOpen( $parser, $name, $attr ) {
35
+    protected function tagOpen($parser, $name, $attr) {
36 36
 
37
-        $this->handleOpenUnit( $name, $attr );
37
+        $this->handleOpenUnit($name, $attr);
38 38
 
39
-        if ( 'mda:metadata' === $name ) {
39
+        if ('mda:metadata' === $name) {
40 40
             $this->unitContainsMda = true;
41 41
         }
42 42
 
43 43
         // check if we are entering into a <target>
44
-        if ( 'target' === $name ) {
44
+        if ('target' === $name) {
45 45
 
46
-            if ( $this->currentTransUnitIsTranslatable === 'no' ) {
46
+            if ($this->currentTransUnitIsTranslatable === 'no') {
47 47
                 $this->inTarget = false;
48 48
             } else {
49 49
                 $this->inTarget = true;
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
         }
52 52
 
53 53
         // open buffer
54
-        if ( in_array( $name, $this->nodesToBuffer ) ) {
54
+        if (in_array($name, $this->nodesToBuffer)) {
55 55
             $this->bufferIsActive = true;
56 56
         }
57 57
 
58 58
         // check if we are inside a <target>, obviously this happen only if there are targets inside the trans-unit
59 59
         // <target> must be stripped to be replaced, so this check avoids <target> reconstruction
60
-        if ( !$this->inTarget ) {
60
+        if (!$this->inTarget) {
61 61
 
62 62
             $tag = '';
63 63
 
@@ -80,31 +80,31 @@  discard block
 block discarded – undo
80 80
             // http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#unit
81 81
             //
82 82
             if (
83
-                    ( $name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable' ) &&
83
+                    ($name === 'notes' || $name === 'originalData' || $name === 'segment' || $name === 'ignorable') &&
84 84
                     $this->unitContainsMda === false &&
85
-                    !empty( $this->transUnits[ $this->currentTransUnitId ] ) &&
85
+                    !empty($this->transUnits[$this->currentTransUnitId]) &&
86 86
                     !$this->hasWrittenCounts
87 87
             ) {
88 88
                 // we need to update counts here
89 89
                 $this->updateCounts();
90 90
                 $this->hasWrittenCounts = true;
91
-                $tag                    .= $this->getWordCountGroupForXliffV2();
91
+                $tag .= $this->getWordCountGroupForXliffV2();
92 92
                 $this->unitContainsMda  = true;
93 93
             }
94 94
 
95 95
             // construct tag
96 96
             $tag .= "<$name ";
97 97
 
98
-            foreach ( $attr as $k => $v ) {
98
+            foreach ($attr as $k => $v) {
99 99
 
100 100
                 //if tag name is file, we must replace the target-language attribute
101
-                if ( $name === 'file' && $k === 'target-language' && !empty( $this->targetLang ) ) {
101
+                if ($name === 'file' && $k === 'target-language' && !empty($this->targetLang)) {
102 102
                     //replace Target language with job language provided from constructor
103 103
                     $tag .= "$k=\"$this->targetLang\" ";
104 104
                 } else {
105 105
 
106 106
                     //normal tag flux, put attributes in it but skip for translation state and set the right value for the attribute
107
-                    if ( $k != 'state' ) {
107
+                    if ($k != 'state') {
108 108
                         $tag .= "$k=\"$v\" ";
109 109
                     }
110 110
 
@@ -114,39 +114,39 @@  discard block
 block discarded – undo
114 114
 
115 115
             $seg = $this->getCurrentSegment();
116 116
 
117
-            if ( $name === $this->tuTagName and !empty( $seg ) and isset( $seg[ 'sid' ] ) ) {
117
+            if ($name === $this->tuTagName and !empty($seg) and isset($seg['sid'])) {
118 118
 
119 119
                 // add `help-id` to xliff v.1*
120 120
                 // add `mtc:segment-id` to xliff v.2*
121
-                if ( strpos( $tag, 'mtc:segment-id' ) === false ) {
122
-                    $tag .= "mtc:segment-id=\"{$seg[ 'sid' ]}\" ";
121
+                if (strpos($tag, 'mtc:segment-id') === false) {
122
+                    $tag .= "mtc:segment-id=\"{$seg['sid']}\" ";
123 123
                 }
124 124
 
125 125
             }
126 126
 
127 127
             // replace state for xliff v2
128
-            if ( 'segment' === $name ) { // add state to segment in Xliff v2
129
-                [ $stateProp, ] = StatusToStateAttribute::getState( $seg[ 'status' ], $this->xliffVersion );
128
+            if ('segment' === $name) { // add state to segment in Xliff v2
129
+                [$stateProp, ] = StatusToStateAttribute::getState($seg['status'], $this->xliffVersion);
130 130
                 $tag .= $stateProp;
131 131
             }
132 132
 
133 133
 
134 134
             // add oasis xliff 20 namespace
135
-            if ( $name === 'xliff' && !array_key_exists( 'xmlns:mda', $attr ) ) {
135
+            if ($name === 'xliff' && !array_key_exists('xmlns:mda', $attr)) {
136 136
                 $tag .= 'xmlns:mda="urn:oasis:names:tc:xliff:metadata:2.0"';
137 137
             }
138 138
 
139 139
             // add MateCat specific namespace, we want maybe add non-XLIFF attributes
140
-            if ( $name === 'xliff' && !array_key_exists( 'xmlns:mtc', $attr ) ) {
140
+            if ($name === 'xliff' && !array_key_exists('xmlns:mtc', $attr)) {
141 141
                 $tag .= ' xmlns:mtc="https://www.matecat.com" ';
142 142
             }
143 143
 
144 144
             // trgLang
145
-            if ( $name === 'xliff' ) {
146
-                $tag = preg_replace( '/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag );
145
+            if ($name === 'xliff') {
146
+                $tag = preg_replace('/trgLang="(.*?)"/', 'trgLang="' . $this->targetLang . '"', $tag);
147 147
             }
148 148
 
149
-            $this->checkForSelfClosedTagAndFlush( $parser, $tag );
149
+            $this->checkForSelfClosedTagAndFlush($parser, $tag);
150 150
 
151 151
         }
152 152
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
     /**
156 156
      * @inheritDoc
157 157
      */
158
-    protected function tagClose( $parser, $name ) {
158
+    protected function tagClose($parser, $name) {
159 159
         $tag = '';
160 160
 
161 161
         /**
@@ -164,32 +164,32 @@  discard block
 block discarded – undo
164 164
          *
165 165
          * self::tagOpen method
166 166
          */
167
-        if ( !$this->isEmpty ) {
167
+        if (!$this->isEmpty) {
168 168
 
169
-            if ( !$this->inTarget ) {
169
+            if (!$this->inTarget) {
170 170
                 $tag = "</$name>";
171 171
             }
172 172
 
173
-            if ( 'target' == $name ) {
173
+            if ('target' == $name) {
174 174
 
175
-                if ( isset( $this->transUnits[ $this->currentTransUnitId ] ) && $this->currentTransUnitIsTranslatable !== 'no' ) {
175
+                if (isset($this->transUnits[$this->currentTransUnitId]) && $this->currentTransUnitIsTranslatable !== 'no') {
176 176
 
177 177
                     $seg = $this->getCurrentSegment();
178 178
 
179 179
                     // update counts
180
-                    if ( !$this->hasWrittenCounts && !empty( $seg ) ) {
181
-                        $this->updateSegmentCounts( $seg );
180
+                    if (!$this->hasWrittenCounts && !empty($seg)) {
181
+                        $this->updateSegmentCounts($seg);
182 182
                     }
183 183
 
184 184
                     // delete translations so the prepareSegment
185 185
                     // will put source content in target tag
186
-                    if ( $this->sourceInTarget ) {
187
-                        $seg[ 'translation' ] = '';
186
+                    if ($this->sourceInTarget) {
187
+                        $seg['translation'] = '';
188 188
                         $this->resetCounts();
189 189
                     }
190 190
 
191 191
                     // append $translation
192
-                    $translation = $this->prepareTranslation( $seg );
192
+                    $translation = $this->prepareTranslation($seg);
193 193
 
194 194
                     //append translation
195 195
                     $tag = "<target>$translation</target>";
@@ -199,21 +199,21 @@  discard block
 block discarded – undo
199 199
                 // signal we are leaving a target
200 200
                 $this->targetWasWritten = true;
201 201
                 $this->inTarget         = false;
202
-                $this->postProcAndFlush( $this->outputFP, $tag, true );
203
-            } elseif ( in_array( $name, $this->nodesToBuffer ) ) { // we are closing a critical CDATA section
202
+                $this->postProcAndFlush($this->outputFP, $tag, true);
203
+            } elseif (in_array($name, $this->nodesToBuffer)) { // we are closing a critical CDATA section
204 204
 
205 205
                 $this->bufferIsActive = false;
206 206
 
207 207
                 // only for Xliff 2.*
208 208
                 // write here <mda:metaGroup> and <mda:meta> if already present in the <unit>
209
-                if ( 'mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts ) {
209
+                if ('mda:metadata' === $name && $this->unitContainsMda && !$this->hasWrittenCounts) {
210 210
 
211 211
                     // we need to update counts here
212 212
                     $this->updateCounts();
213 213
                     $this->hasWrittenCounts = true;
214 214
 
215 215
                     $tag = $this->CDATABuffer;
216
-                    $tag .= $this->getWordCountGroupForXliffV2( false );
216
+                    $tag .= $this->getWordCountGroupForXliffV2(false);
217 217
                     $tag .= "    </mda:metadata>";
218 218
 
219 219
                 } else {
@@ -223,19 +223,19 @@  discard block
 block discarded – undo
223 223
                 $this->CDATABuffer = "";
224 224
 
225 225
                 //flush to the pointer
226
-                $this->postProcAndFlush( $this->outputFP, $tag );
226
+                $this->postProcAndFlush($this->outputFP, $tag);
227 227
 
228
-            } elseif ( 'segment' === $name ) {
228
+            } elseif ('segment' === $name) {
229 229
 
230 230
                 // only for Xliff 2.*
231 231
                 // if segment has no <target> add it BEFORE </segment>
232
-                if ( !$this->targetWasWritten ) {
232
+                if (!$this->targetWasWritten) {
233 233
 
234 234
                     $seg = $this->getCurrentSegment();
235 235
 
236
-                    if ( isset( $seg[ 'translation' ] ) ) {
236
+                    if (isset($seg['translation'])) {
237 237
 
238
-                        $translation = $this->prepareTranslation( $seg );
238
+                        $translation = $this->prepareTranslation($seg);
239 239
                         // replace the tag
240 240
                         $tag = "<target>$translation</target>";
241 241
 
@@ -248,17 +248,17 @@  discard block
 block discarded – undo
248 248
                 // update segmentPositionInTu
249 249
                 $this->segmentInUnitPosition++;
250 250
 
251
-                $this->postProcAndFlush( $this->outputFP, $tag );
251
+                $this->postProcAndFlush($this->outputFP, $tag);
252 252
 
253 253
                 // we are leaving <segment>, reset $segmentHasTarget
254 254
                 $this->targetWasWritten = false;
255 255
 
256
-            } elseif ( $this->bufferIsActive ) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
256
+            } elseif ($this->bufferIsActive) { // this is a tag ( <g | <mrk ) inside a seg or seg-source tag
257 257
                 $this->CDATABuffer .= "</$name>";
258 258
                 // Do NOT Flush
259 259
             } else { //generic tag closure do Nothing
260 260
                 // flush to pointer
261
-                $this->postProcAndFlush( $this->outputFP, $tag );
261
+                $this->postProcAndFlush($this->outputFP, $tag);
262 262
             }
263 263
         } else {
264 264
             //ok, nothing to be done; reset flag for next coming tag
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         }
267 267
 
268 268
         // check if we are leaving a <trans-unit> (xliff v1.*) or <unit> (xliff v2.*)
269
-        if ( $this->tuTagName === $name ) {
269
+        if ($this->tuTagName === $name) {
270 270
             $this->currentTransUnitIsTranslatable = null;
271 271
             $this->inTU                           = false;
272 272
             $this->segmentPositionInTu            = -1;
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
     private function updateCounts() {
284 284
 
285 285
         $seg = $this->getCurrentSegment();
286
-        if ( !empty( $seg ) ) {
287
-            $this->updateSegmentCounts( $seg );
286
+        if (!empty($seg)) {
287
+            $this->updateSegmentCounts($seg);
288 288
         }
289 289
 
290 290
     }
@@ -294,30 +294,30 @@  discard block
 block discarded – undo
294 294
      *
295 295
      * @return string
296 296
      */
297
-    private function getWordCountGroupForXliffV2( bool $withMetadataTag = true ): string {
297
+    private function getWordCountGroupForXliffV2(bool $withMetadataTag = true): string {
298 298
 
299 299
         $this->mdaGroupCounter++;
300
-        $segments_count_array = $this->counts[ 'segments_count_array' ];
300
+        $segments_count_array = $this->counts['segments_count_array'];
301 301
 
302 302
         $tag = '';
303 303
 
304
-        if ( $withMetadataTag === true ) {
304
+        if ($withMetadataTag === true) {
305 305
             $tag .= '<mda:metadata>';
306 306
         }
307 307
 
308 308
         $index = 0;
309
-        foreach ( $segments_count_array as $segments_count_item ) {
309
+        foreach ($segments_count_array as $segments_count_item) {
310 310
 
311 311
             $id = 'word_count_tu[' . $this->currentTransUnitId . '][' . $index . ']';
312 312
             $index++;
313 313
 
314 314
             $tag .= "    <mda:metaGroup id=\"" . $id . "\" category=\"row_xml_attribute\">
315
-                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item[ 'raw_word_count' ] . "</mda:meta>
316
-                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item[ 'eq_word_count' ] . "</mda:meta>
315
+                                <mda:meta type=\"x-matecat-raw\">" . $segments_count_item['raw_word_count'] . "</mda:meta>
316
+                                <mda:meta type=\"x-matecat-weighted\">" . $segments_count_item['eq_word_count'] . "</mda:meta>
317 317
                             </mda:metaGroup>";
318 318
         }
319 319
 
320
-        if ( $withMetadataTag === true ) {
320
+        if ($withMetadataTag === true) {
321 321
             $tag .= '</mda:metadata>';
322 322
         }
323 323
 
@@ -332,18 +332,18 @@  discard block
 block discarded – undo
332 332
      *
333 333
      * @return string
334 334
      */
335
-    protected function prepareTranslation( array $seg ): string {
335
+    protected function prepareTranslation(array $seg): string {
336 336
 
337
-        $segment     = Strings::removeDangerousChars( $seg [ 'segment' ] );
338
-        $translation = Strings::removeDangerousChars( $seg [ 'translation' ] );
339
-        $dataRefMap  = ( isset( $seg[ 'data_ref_map' ] ) ) ? Strings::jsonToArray( $seg[ 'data_ref_map' ] ) : [];
337
+        $segment     = Strings::removeDangerousChars($seg ['segment']);
338
+        $translation = Strings::removeDangerousChars($seg ['translation']);
339
+        $dataRefMap  = (isset($seg['data_ref_map'])) ? Strings::jsonToArray($seg['data_ref_map']) : [];
340 340
 
341
-        if ( $seg [ 'translation' ] == '' ) {
341
+        if ($seg ['translation'] == '') {
342 342
             $translation = $segment;
343 343
         } else {
344
-            if ( $this->callback instanceof XliffReplacerCallbackInterface ) {
345
-                $error = ( !empty( $seg[ 'error' ] ) ) ? $seg[ 'error' ] : null;
346
-                if ( $this->callback->thereAreErrors( $seg[ 'sid' ], $segment, $translation, $dataRefMap, $error ) ) {
344
+            if ($this->callback instanceof XliffReplacerCallbackInterface) {
345
+                $error = (!empty($seg['error'])) ? $seg['error'] : null;
346
+                if ($this->callback->thereAreErrors($seg['sid'], $segment, $translation, $dataRefMap, $error)) {
347 347
                     $translation = '|||UNTRANSLATED_CONTENT_START|||' . $segment . '|||UNTRANSLATED_CONTENT_END|||';
348 348
                 }
349 349
             }
Please login to merge, or discard this patch.