Passed
Push — master ( bcc00c...e0573b )
by Domenico
03:31
created
src/XliffParser.php 1 patch
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      *
25 25
      * @param LoggerInterface $logger
26 26
      */
27
-    public function __construct( LoggerInterface $logger = null ) {
27
+    public function __construct(LoggerInterface $logger = null) {
28 28
         $this->logger = $logger;
29 29
     }
30 30
 
@@ -39,11 +39,11 @@  discard block
 block discarded – undo
39 39
      * @param bool                                $setSourceInTarget
40 40
      * @param XliffReplacerCallbackInterface|null $callback
41 41
      */
42
-    public function replaceTranslation( $originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null ) {
42
+    public function replaceTranslation($originalXliffPath, &$data, &$transUnits, $targetLang, $outputFile, $setSourceInTarget = false, XliffReplacerCallbackInterface $callback = null) {
43 43
         try {
44
-            $parser = XliffReplacerFactory::getInstance( $originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback );
44
+            $parser = XliffReplacerFactory::getInstance($originalXliffPath, $data, $transUnits, $targetLang, $outputFile, $setSourceInTarget, $this->logger, $callback);
45 45
             $parser->replaceTranslation();
46
-        } catch ( \Exception $exception ) {
46
+        } catch (\Exception $exception) {
47 47
             // do nothing
48 48
         }
49 49
     }
@@ -61,29 +61,29 @@  discard block
 block discarded – undo
61 61
      * @throws Exception\NotValidFileException
62 62
      * @throws Exception\XmlParsingException
63 63
      */
64
-    public function xliffToArray( $xliffContent, $collapseEmptyTags = false ) {
64
+    public function xliffToArray($xliffContent, $collapseEmptyTags = false) {
65 65
         $xliff        = [];
66
-        $xliffContent = self::forceUft8Encoding( $xliffContent, $xliff );
67
-        $xliffVersion = XliffVersionDetector::detect( $xliffContent );
68
-        $info         = XliffProprietaryDetect::getInfoFromXliffContent( $xliffContent );
66
+        $xliffContent = self::forceUft8Encoding($xliffContent, $xliff);
67
+        $xliffVersion = XliffVersionDetector::detect($xliffContent);
68
+        $info         = XliffProprietaryDetect::getInfoFromXliffContent($xliffContent);
69 69
 
70
-        if ( $xliffVersion === 1 ) {
71
-            $xliffContent = self::removeInternalFileTagFromContent( $xliffContent, $xliff );
70
+        if ($xliffVersion === 1) {
71
+            $xliffContent = self::removeInternalFileTagFromContent($xliffContent, $xliff);
72 72
         }
73 73
 
74
-        if ( $xliffVersion === 2 ) {
75
-            $xliffContent = self::escapeDataInOriginalMap( $xliffContent );
74
+        if ($xliffVersion === 2) {
75
+            $xliffContent = self::escapeDataInOriginalMap($xliffContent);
76 76
         }
77 77
 
78
-        if ( $collapseEmptyTags === false ) {
79
-            $xliffContent = self::insertPlaceholderInEmptyTags( $xliffContent );
78
+        if ($collapseEmptyTags === false) {
79
+            $xliffContent = self::insertPlaceholderInEmptyTags($xliffContent);
80 80
         }
81 81
 
82
-        $xliffProprietary = ( isset( $info[ 'proprietary_short_name' ] ) && null !== $info[ 'proprietary_short_name' ] ) ? $info[ 'proprietary_short_name' ] : null;
83
-        $parser           = XliffParserFactory::getInstance( $xliffVersion, $xliffProprietary, $this->logger );
84
-        $dom              = XmlParser::parse( $xliffContent );
82
+        $xliffProprietary = (isset($info['proprietary_short_name']) && null !== $info['proprietary_short_name']) ? $info['proprietary_short_name'] : null;
83
+        $parser           = XliffParserFactory::getInstance($xliffVersion, $xliffProprietary, $this->logger);
84
+        $dom              = XmlParser::parse($xliffContent);
85 85
 
86
-        return $parser->parse( $dom, $xliff );
86
+        return $parser->parse($dom, $xliff);
87 87
     }
88 88
 
89 89
     /**
@@ -95,12 +95,12 @@  discard block
 block discarded – undo
95 95
      *
96 96
      * @return string
97 97
      */
98
-    private static function forceUft8Encoding( $xliffContent, &$xliff ) {
99
-        $enc = mb_detect_encoding( $xliffContent );
98
+    private static function forceUft8Encoding($xliffContent, &$xliff) {
99
+        $enc = mb_detect_encoding($xliffContent);
100 100
 
101
-        if ( $enc !== 'UTF-8' ) {
102
-            $xliff[ 'parser-warnings' ][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only";
103
-            $s                            = iconv( $enc, 'UTF-8', $xliffContent );
101
+        if ($enc !== 'UTF-8') {
102
+            $xliff['parser-warnings'][] = "Input identified as $enc ans converted UTF-8. May not be a problem if the content is English only";
103
+            $s                            = iconv($enc, 'UTF-8', $xliffContent);
104 104
             $xliffContent                 = $s !== false ? $s : "";
105 105
         }
106 106
 
@@ -117,24 +117,24 @@  discard block
 block discarded – undo
117 117
      *
118 118
      * @return mixed|string
119 119
      */
120
-    private static function removeInternalFileTagFromContent( $xliffContent, &$xliff ) {
120
+    private static function removeInternalFileTagFromContent($xliffContent, &$xliff) {
121 121
         $index = 1;
122
-        $a     = Strings::preg_split( '|<internal-file[\s>]|si', $xliffContent );
122
+        $a     = Strings::preg_split('|<internal-file[\s>]|si', $xliffContent);
123 123
 
124 124
         // no match, return original string
125
-        if ( count( $a ) === 1 ) {
126
-            return $a[ 0 ];
125
+        if (count($a) === 1) {
126
+            return $a[0];
127 127
         }
128 128
 
129
-        $b                                           = Strings::preg_split( '|</internal-file>|si', $a[ 1 ] );
130
-        $strippedContent                             = $a[ 0 ] . $b[ 1 ];
131
-        $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $b[ 0 ] );
129
+        $b                                           = Strings::preg_split('|</internal-file>|si', $a[1]);
130
+        $strippedContent                             = $a[0] . $b[1];
131
+        $xliff['files'][$index]['reference'][] = self::extractBase64($b[0]);
132 132
         $index++;
133 133
 
134
-        if ( isset( $a[ 2 ] ) ) {
135
-            $c                                           = Strings::preg_split( '|</internal-file[\s>]|si', $a[ 2 ] );
136
-            $strippedContent                             .= $c[ 1 ];
137
-            $xliff[ 'files' ][ $index ][ 'reference' ][] = self::extractBase64( $c[ 0 ] );
134
+        if (isset($a[2])) {
135
+            $c                                           = Strings::preg_split('|</internal-file[\s>]|si', $a[2]);
136
+            $strippedContent .= $c[1];
137
+            $xliff['files'][$index]['reference'][] = self::extractBase64($c[0]);
138 138
         }
139 139
 
140 140
         return $strippedContent;
@@ -145,10 +145,10 @@  discard block
 block discarded – undo
145 145
      *
146 146
      * @return array
147 147
      */
148
-    private static function extractBase64( $base64 ) {
148
+    private static function extractBase64($base64) {
149 149
         return [
150 150
                 'form-type' => 'base64',
151
-                'base64'    => trim( str_replace( 'form="base64">', '', $base64 ) ),
151
+                'base64'    => trim(str_replace('form="base64">', '', $base64)),
152 152
         ];
153 153
     }
154 154
 
@@ -168,9 +168,9 @@  discard block
 block discarded – undo
168 168
      *
169 169
      * @return string
170 170
      */
171
-    private static function escapeDataInOriginalMap( $xliffContent ) {
172
-        $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceSpace' ], $xliffContent );
173
-        $xliffContent = preg_replace_callback( '/<data(.*?)>(.*?)<\/data>/iU', [ XliffParser::class, 'replaceXliffTags' ], $xliffContent );
171
+    private static function escapeDataInOriginalMap($xliffContent) {
172
+        $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceSpace'], $xliffContent);
173
+        $xliffContent = preg_replace_callback('/<data(.*?)>(.*?)<\/data>/iU', [XliffParser::class, 'replaceXliffTags'], $xliffContent);
174 174
 
175 175
         return $xliffContent;
176 176
     }
@@ -189,15 +189,15 @@  discard block
 block discarded – undo
189 189
      *
190 190
      * @return string
191 191
      */
192
-    private static function insertPlaceholderInEmptyTags( $xliffContent ) {
193
-        preg_match_all( '/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches );
192
+    private static function insertPlaceholderInEmptyTags($xliffContent) {
193
+        preg_match_all('/<([a-zA-Z0-9._-]+)[^>]*><\/\1>/sm', $xliffContent, $emptyTagMatches);
194 194
 
195
-        if ( !empty( $emptyTagMatches[ 0 ] ) ) {
196
-            foreach ( $emptyTagMatches[ 0 ] as $index => $emptyTagMatch ) {
197
-                $matchedTag   = $emptyTagMatches[ 1 ][ $index ];
195
+        if (!empty($emptyTagMatches[0])) {
196
+            foreach ($emptyTagMatches[0] as $index => $emptyTagMatch) {
197
+                $matchedTag   = $emptyTagMatches[1][$index];
198 198
                 $subst        = Placeholder::EMPTY_TAG_PLACEHOLDER . '</' . $matchedTag . '>';
199
-                $replacedTag  = str_replace( '</' . $matchedTag . '>', $subst, $emptyTagMatch );
200
-                $xliffContent = str_replace( $emptyTagMatch, $replacedTag, $xliffContent );
199
+                $replacedTag  = str_replace('</' . $matchedTag . '>', $subst, $emptyTagMatch);
200
+                $xliffContent = str_replace($emptyTagMatch, $replacedTag, $xliffContent);
201 201
             }
202 202
         }
203 203
 
@@ -211,12 +211,12 @@  discard block
 block discarded – undo
211 211
      *
212 212
      * @return string
213 213
      */
214
-    private static function replaceSpace( $matches ) {
215
-        $content = str_replace( ' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[ 2 ] );
216
-        $content = str_replace( '\n', Placeholder::NEW_LINE_PLACEHOLDER, $content );
217
-        $content = str_replace( '\t', Placeholder::TAB_PLACEHOLDER, $content );
214
+    private static function replaceSpace($matches) {
215
+        $content = str_replace(' ', Placeholder::WHITE_SPACE_PLACEHOLDER, $matches[2]);
216
+        $content = str_replace('\n', Placeholder::NEW_LINE_PLACEHOLDER, $content);
217
+        $content = str_replace('\t', Placeholder::TAB_PLACEHOLDER, $content);
218 218
 
219
-        return '<data' . $matches[ 1 ] . '>' . $content . '</data>';
219
+        return '<data' . $matches[1] . '>' . $content . '</data>';
220 220
     }
221 221
 
222 222
     /**
@@ -224,15 +224,15 @@  discard block
 block discarded – undo
224 224
      *
225 225
      * @return string
226 226
      */
227
-    private static function replaceXliffTags( $matches ) {
227
+    private static function replaceXliffTags($matches) {
228 228
         $xliffTags = XliffTags::$tags;
229
-        $content   = $matches[ 2 ];
229
+        $content   = $matches[2];
230 230
 
231
-        foreach ( $xliffTags as $xliffTag ) {
232
-            $content = preg_replace( '|&lt;(' . $xliffTag . '.*?)&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content );
233
-            $content = preg_replace( '|&lt;(/' . $xliffTag . ')&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content );
231
+        foreach ($xliffTags as $xliffTag) {
232
+            $content = preg_replace('|&lt;(' . $xliffTag . '.*?)&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content);
233
+            $content = preg_replace('|&lt;(/' . $xliffTag . ')&gt;|si', Placeholder::LT_PLACEHOLDER . "$1" . Placeholder::GT_PLACEHOLDER, $content);
234 234
         }
235 235
 
236
-        return '<data' . $matches[ 1 ] . '>' . $content . '</data>';
236
+        return '<data' . $matches[1] . '>' . $content . '</data>';
237 237
     }
238 238
 }
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 mixed
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/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/Utils/Emoji.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -7401,7 +7401,7 @@
 block discarded – undo
7401 7401
             '
Please login to merge, or discard this patch.