Passed
Push — master ( f3b854...2c0ba9 )
by Domenico
08:46
created
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.