@@ -17,8 +17,8 @@ discard block |
||
| 17 | 17 | * @return string |
| 18 | 18 | * @throws Exception |
| 19 | 19 | */ |
| 20 | - public static function cleanCDATA( string $testString ): string { |
|
| 21 | - $cleanXMLContent = new SimpleXMLElement( '<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA ); |
|
| 20 | + public static function cleanCDATA(string $testString): string { |
|
| 21 | + $cleanXMLContent = new SimpleXMLElement('<rootNoteNode>' . $testString . '</rootNoteNode>', LIBXML_NOCDATA); |
|
| 22 | 22 | |
| 23 | 23 | return $cleanXMLContent->__toString(); |
| 24 | 24 | } |
@@ -28,28 +28,28 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @return bool |
| 30 | 30 | */ |
| 31 | - public static function isJSON( string $string ): bool { |
|
| 32 | - if ( is_numeric( $string ) ) { |
|
| 31 | + public static function isJSON(string $string): bool { |
|
| 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 |
||
| 61 | 61 | * |
| 62 | 62 | * @return array |
| 63 | 63 | */ |
| 64 | - public static function jsonToArray( string $string ): array { |
|
| 65 | - $decodedJSON = json_decode( $string, true ); |
|
| 64 | + public static function jsonToArray(string $string): array { |
|
| 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 | /** |
@@ -73,10 +73,10 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | private static function raiseLastJsonException() { |
| 75 | 75 | |
| 76 | - [ $msg, $error ] = self::getLastJsonError(); |
|
| 76 | + [$msg, $error] = self::getLastJsonError(); |
|
| 77 | 77 | |
| 78 | - if ( $error != JSON_ERROR_NONE ) { |
|
| 79 | - throw new NotValidJSONException( $msg, $error ); |
|
| 78 | + if ($error != JSON_ERROR_NONE) { |
|
| 79 | + throw new NotValidJSONException($msg, $error); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | } |
@@ -86,11 +86,11 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | private static function getLastJsonError(): array { |
| 88 | 88 | |
| 89 | - if ( function_exists( "json_last_error" ) ) { |
|
| 89 | + if (function_exists("json_last_error")) { |
|
| 90 | 90 | |
| 91 | 91 | $error = json_last_error(); |
| 92 | 92 | |
| 93 | - switch ( $error ) { |
|
| 93 | + switch ($error) { |
|
| 94 | 94 | case JSON_ERROR_NONE: |
| 95 | 95 | $msg = null; # - No errors |
| 96 | 96 | break; |
@@ -114,10 +114,10 @@ discard block |
||
| 114 | 114 | break; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - return [ $msg, $error ]; |
|
| 117 | + return [$msg, $error]; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - return [ null, JSON_ERROR_NONE ]; |
|
| 120 | + return [null, JSON_ERROR_NONE]; |
|
| 121 | 121 | |
| 122 | 122 | } |
| 123 | 123 | |
@@ -140,11 +140,11 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | - public static function fixNonWellFormedXml( string $content, ?bool $escapeStrings = true ): string { |
|
| 144 | - if ( self::$find_xliff_tags_reg === null ) { |
|
| 143 | + public static function fixNonWellFormedXml(string $content, ?bool $escapeStrings = true): string { |
|
| 144 | + if (self::$find_xliff_tags_reg === null) { |
|
| 145 | 145 | // Convert the list of tags in a regexp list, for example "g|x|bx|ex" |
| 146 | 146 | $xliffTags = XliffTags::$tags; |
| 147 | - $xliff_tags_reg_list = implode( '|', $xliffTags ); |
|
| 147 | + $xliff_tags_reg_list = implode('|', $xliffTags); |
|
| 148 | 148 | // Regexp to find all the XLIFF tags: |
| 149 | 149 | // </? -> matches the tag start, for both opening and |
| 150 | 150 | // closure tags (see the optional slash) |
@@ -165,30 +165,30 @@ discard block |
||
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | // Find all the XLIFF tags |
| 168 | - preg_match_all( self::$find_xliff_tags_reg, $content, $matches ); |
|
| 169 | - $tags = (array)$matches[ 0 ]; |
|
| 168 | + preg_match_all(self::$find_xliff_tags_reg, $content, $matches); |
|
| 169 | + $tags = (array)$matches[0]; |
|
| 170 | 170 | |
| 171 | 171 | // Prepare placeholders |
| 172 | 172 | $tags_placeholders = []; |
| 173 | - $tagsNum = count( $tags ); |
|
| 174 | - for ( $i = 0; $i < $tagsNum; $i++ ) { |
|
| 175 | - $tag = $tags[ $i ]; |
|
| 176 | - $tags_placeholders[ $tag ] = "#@!XLIFF-TAG-$i!@#"; |
|
| 173 | + $tagsNum = count($tags); |
|
| 174 | + for ($i = 0; $i < $tagsNum; $i++) { |
|
| 175 | + $tag = $tags[$i]; |
|
| 176 | + $tags_placeholders[$tag] = "#@!XLIFF-TAG-$i!@#"; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | // Replace all XLIFF tags with placeholders that will not be escaped |
| 180 | - foreach ( $tags_placeholders as $tag => $placeholder ) { |
|
| 181 | - $content = str_replace( $tag, $placeholder, $content ); |
|
| 180 | + foreach ($tags_placeholders as $tag => $placeholder) { |
|
| 181 | + $content = str_replace($tag, $placeholder, $content); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Escape the string with the remaining non-XLIFF tags |
| 185 | - if ( $escapeStrings ) { |
|
| 186 | - $content = htmlspecialchars( $content, ENT_NOQUOTES, 'UTF-8', false ); |
|
| 185 | + if ($escapeStrings) { |
|
| 186 | + $content = htmlspecialchars($content, ENT_NOQUOTES, 'UTF-8', false); |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | // Put again in place the original XLIFF tags replacing placeholders |
| 190 | - foreach ( $tags_placeholders as $tag => $placeholder ) { |
|
| 191 | - $content = str_replace( $placeholder, $tag, $content ); |
|
| 190 | + foreach ($tags_placeholders as $tag => $placeholder) { |
|
| 191 | + $content = str_replace($placeholder, $tag, $content); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | return $content; |
@@ -199,17 +199,17 @@ discard block |
||
| 199 | 199 | * |
| 200 | 200 | * @return string |
| 201 | 201 | */ |
| 202 | - public static function removeDangerousChars( $string ): string { |
|
| 202 | + public static function removeDangerousChars($string): string { |
|
| 203 | 203 | // clean invalid xml entities ( characters with ascii < 32 and different from 0A, 0D and 09 |
| 204 | 204 | $regexpEntity = '/&#x(0[0-8BCEF]|1[\dA-F]|7F);/u'; |
| 205 | 205 | |
| 206 | 206 | // remove binary chars in some xliff files |
| 207 | 207 | $regexpAscii = '/[\x{00}-\x{08}\x{0B}\x{0C}\x{0E}-\x{1F}\x{7F}]/u'; |
| 208 | 208 | |
| 209 | - $string = preg_replace( $regexpAscii, '', $string ?? '' ); |
|
| 210 | - $string = preg_replace( $regexpEntity, '', $string ?? '' ); |
|
| 209 | + $string = preg_replace($regexpAscii, '', $string ?? ''); |
|
| 210 | + $string = preg_replace($regexpEntity, '', $string ?? ''); |
|
| 211 | 211 | |
| 212 | - return !empty( $string ) || strlen( $string ) > 0 ? $string : ""; |
|
| 212 | + return !empty($string) || strlen($string) > 0 ? $string : ""; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -219,15 +219,15 @@ discard block |
||
| 219 | 219 | * |
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | - public static function htmlspecialchars_decode( string $string, ?bool $onlyEscapedEntities = false ): string { |
|
| 223 | - if ( false === $onlyEscapedEntities ) { |
|
| 224 | - return htmlspecialchars_decode( $string, ENT_NOQUOTES ); |
|
| 222 | + public static function htmlspecialchars_decode(string $string, ?bool $onlyEscapedEntities = false): string { |
|
| 223 | + if (false === $onlyEscapedEntities) { |
|
| 224 | + return htmlspecialchars_decode($string, ENT_NOQUOTES); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | - return preg_replace_callback( self::$htmlEntityRegex, |
|
| 228 | - function ( $match ) { |
|
| 229 | - return self::htmlspecialchars_decode( $match[ 0 ] ); |
|
| 230 | - }, $string ); |
|
| 227 | + return preg_replace_callback(self::$htmlEntityRegex, |
|
| 228 | + function($match) { |
|
| 229 | + return self::htmlspecialchars_decode($match[0]); |
|
| 230 | + }, $string); |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -242,8 +242,8 @@ discard block |
||
| 242 | 242 | * |
| 243 | 243 | * @return bool |
| 244 | 244 | */ |
| 245 | - public static function isADoubleEscapedEntity( string $str ): bool { |
|
| 246 | - return preg_match( self::$htmlEntityRegex, $str ) != 0; |
|
| 245 | + public static function isADoubleEscapedEntity(string $str): bool { |
|
| 246 | + return preg_match(self::$htmlEntityRegex, $str) != 0; |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | /** |
@@ -251,8 +251,8 @@ discard block |
||
| 251 | 251 | * |
| 252 | 252 | * @return bool |
| 253 | 253 | */ |
| 254 | - public static function isAValidUuid( $uuid ) { |
|
| 255 | - return preg_match( '/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid ) === 1; |
|
| 254 | + public static function isAValidUuid($uuid) { |
|
| 255 | + return preg_match('/^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/', $uuid) === 1; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | /** |
@@ -261,8 +261,8 @@ discard block |
||
| 261 | 261 | * |
| 262 | 262 | * @return array|false|string[] |
| 263 | 263 | */ |
| 264 | - public static function preg_split( $pattern, $subject ) { |
|
| 265 | - return preg_split( $pattern, $subject, -1, PREG_SPLIT_NO_EMPTY ); |
|
| 264 | + public static function preg_split($pattern, $subject) { |
|
| 265 | + return preg_split($pattern, $subject, -1, PREG_SPLIT_NO_EMPTY); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | /** |
@@ -270,8 +270,8 @@ discard block |
||
| 270 | 270 | * |
| 271 | 271 | * @return int |
| 272 | 272 | */ |
| 273 | - public static function getTheNumberOfTrailingSpaces( $segment ): int { |
|
| 274 | - return mb_strlen( $segment ) - mb_strlen( rtrim( $segment, ' ' ) ); |
|
| 273 | + public static function getTheNumberOfTrailingSpaces($segment): int { |
|
| 274 | + return mb_strlen($segment) - mb_strlen(rtrim($segment, ' ')); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | } |