@@ -26,10 +26,8 @@ discard block |
||
| 26 | 26 | { |
| 27 | 27 | if ($this->startsWith($substring)) |
| 28 | 28 | { |
| 29 | - return $this->newSelf |
|
| 30 | - ( |
|
| 31 | - UTF8::substr |
|
| 32 | - ( |
|
| 29 | + return $this->newSelf( |
|
| 30 | + UTF8::substr( |
|
| 33 | 31 | $this->scalarString, |
| 34 | 32 | UTF8::strlen($substring, $this->encoding), |
| 35 | 33 | null, |
@@ -52,10 +50,8 @@ discard block |
||
| 52 | 50 | { |
| 53 | 51 | if ($this->endsWith($substring)) |
| 54 | 52 | { |
| 55 | - return $this->newSelf |
|
| 56 | - ( |
|
| 57 | - UTF8::substr |
|
| 58 | - ( |
|
| 53 | + return $this->newSelf( |
|
| 54 | + UTF8::substr( |
|
| 59 | 55 | $this->scalarString, |
| 60 | 56 | 0, |
| 61 | 57 | $this->getLength() - UTF8::strlen($substring, $this->encoding), |
@@ -36,15 +36,14 @@ discard block |
||
| 36 | 36 | $substringLength = UTF8::strlen($substring, $this->encoding); |
| 37 | 37 | $length -= $substringLength; |
| 38 | 38 | |
| 39 | - $truncated = UTF8::substr |
|
| 40 | - ( |
|
| 39 | + $truncated = UTF8::substr( |
|
| 41 | 40 | $this->scalarString, |
| 42 | 41 | 0, |
| 43 | 42 | $length, |
| 44 | 43 | $this->encoding |
| 45 | 44 | ); |
| 46 | 45 | |
| 47 | - return $this->newSelf($truncated . $substring); |
|
| 46 | + return $this->newSelf($truncated.$substring); |
|
| 48 | 47 | } |
| 49 | 48 | |
| 50 | 49 | /** |
@@ -79,6 +78,6 @@ discard block |
||
| 79 | 78 | $truncated = UTF8::substr($truncated, 0, $lastPos, $this->encoding); |
| 80 | 79 | } |
| 81 | 80 | |
| 82 | - return $this->newSelf($truncated . $substring); |
|
| 81 | + return $this->newSelf($truncated.$substring); |
|
| 83 | 82 | } |
| 84 | 83 | } |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | */ |
| 31 | 31 | public function truncate($length, $substring = '') |
| 32 | 32 | { |
| 33 | - if ($length >= $this->getLength()) return $this; |
|
| 33 | + if ($length >= $this->getLength()) { |
|
| 34 | + return $this; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | // Need to further trim the string so we can append the substring |
| 36 | 38 | $substringLength = UTF8::strlen($substring, $this->encoding); |
@@ -63,7 +65,9 @@ discard block |
||
| 63 | 65 | */ |
| 64 | 66 | public function safeTruncate($length, $substring = '') |
| 65 | 67 | { |
| 66 | - if ($length >= $this->getLength()) return $this; |
|
| 68 | + if ($length >= $this->getLength()) { |
|
| 69 | + return $this; |
|
| 70 | + } |
|
| 67 | 71 | |
| 68 | 72 | // Need to further trim the string so we can append the substring |
| 69 | 73 | $substringLength = UTF8::strlen($substring, $this->encoding); |
@@ -37,8 +37,7 @@ discard block |
||
| 37 | 37 | { |
| 38 | 38 | if (!in_array($padType, ['left', 'right', 'both'], true)) |
| 39 | 39 | { |
| 40 | - throw new \InvalidArgumentException |
|
| 41 | - ( |
|
| 40 | + throw new \InvalidArgumentException( |
|
| 42 | 41 | 'Pad expects $padType '."to be one of 'left', 'right' or 'both'" |
| 43 | 42 | ); |
| 44 | 43 | } |
@@ -118,16 +117,14 @@ discard block |
||
| 118 | 117 | |
| 119 | 118 | if (!$length || $paddedLength <= $strLength) return $this; |
| 120 | 119 | |
| 121 | - $leftPadding = UTF8::substr |
|
| 122 | - ( |
|
| 120 | + $leftPadding = UTF8::substr( |
|
| 123 | 121 | UTF8::str_repeat($padStr, ceil($left / $length)), |
| 124 | 122 | 0, |
| 125 | 123 | $left, |
| 126 | 124 | $this->encoding |
| 127 | 125 | ); |
| 128 | 126 | |
| 129 | - $rightPadding = UTF8::substr |
|
| 130 | - ( |
|
| 127 | + $rightPadding = UTF8::substr( |
|
| 131 | 128 | UTF8::str_repeat($padStr, ceil($right / $length)), |
| 132 | 129 | 0, |
| 133 | 130 | $right, |
@@ -116,7 +116,9 @@ |
||
| 116 | 116 | $strLength = $this->getLength(); |
| 117 | 117 | $paddedLength = $strLength + $left + $right; |
| 118 | 118 | |
| 119 | - if (!$length || $paddedLength <= $strLength) return $this; |
|
| 119 | + if (!$length || $paddedLength <= $strLength) { |
|
| 120 | + return $this; |
|
| 121 | + } |
|
| 120 | 122 | |
| 121 | 123 | $leftPadding = UTF8::substr |
| 122 | 124 | ( |
@@ -72,8 +72,7 @@ |
||
| 72 | 72 | if ($match[0] == $marchToUpper) |
| 73 | 73 | { |
| 74 | 74 | return UTF8::strtolower($match[0], $this->encoding); |
| 75 | - } |
|
| 76 | - else |
|
| 75 | + } else |
|
| 77 | 76 | { |
| 78 | 77 | return $marchToUpper; |
| 79 | 78 | } |
@@ -24,8 +24,7 @@ discard block |
||
| 24 | 24 | { |
| 25 | 25 | $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
| 26 | 26 | |
| 27 | - $rest = UTF8::substr |
|
| 28 | - ( |
|
| 27 | + $rest = UTF8::substr( |
|
| 29 | 28 | $this->scalarString, |
| 30 | 29 | 1, |
| 31 | 30 | $this->getLength() - 1, |
@@ -44,8 +43,7 @@ discard block |
||
| 44 | 43 | { |
| 45 | 44 | $first = UTF8::substr($this->scalarString, 0, 1, $this->encoding); |
| 46 | 45 | |
| 47 | - $rest = UTF8::substr |
|
| 48 | - ( |
|
| 46 | + $rest = UTF8::substr( |
|
| 49 | 47 | $this->scalarString, |
| 50 | 48 | 1, |
| 51 | 49 | $this->getLength() - 1, |
@@ -62,10 +60,9 @@ discard block |
||
| 62 | 60 | */ |
| 63 | 61 | public function swapCase() |
| 64 | 62 | { |
| 65 | - return $this->newSelf(preg_replace_callback |
|
| 66 | - ( |
|
| 63 | + return $this->newSelf(preg_replace_callback( |
|
| 67 | 64 | '/[\S]/u', |
| 68 | - function ($match) |
|
| 65 | + function($match) |
|
| 69 | 66 | { |
| 70 | 67 | $marchToUpper = UTF8::strtoupper($match[0], $this->encoding); |
| 71 | 68 | |
@@ -11,8 +11,6 @@ |
||
| 11 | 11 | // ----------------------------------------------------------------------------- |
| 12 | 12 | //////////////////////////////////////////////////////////////////////////////// |
| 13 | 13 | |
| 14 | -use voku\helper\UTF8; |
|
| 15 | - |
|
| 16 | 14 | trait Trim |
| 17 | 15 | { |
| 18 | 16 | /** |
@@ -11,8 +11,6 @@ |
||
| 11 | 11 | // ----------------------------------------------------------------------------- |
| 12 | 12 | //////////////////////////////////////////////////////////////////////////////// |
| 13 | 13 | |
| 14 | -use voku\helper\UTF8; |
|
| 15 | - |
|
| 16 | 14 | trait Trim |
| 17 | 15 | { |
| 18 | 16 | /** |
@@ -88,7 +88,9 @@ discard block |
||
| 88 | 88 | */ |
| 89 | 89 | public function isJson() |
| 90 | 90 | { |
| 91 | - if ($this->getLength() === 0) return false; |
|
| 91 | + if ($this->getLength() === 0) { |
|
| 92 | + return false; |
|
| 93 | + } |
|
| 92 | 94 | |
| 93 | 95 | json_decode($this->scalarString); |
| 94 | 96 | |
@@ -102,7 +104,9 @@ discard block |
||
| 102 | 104 | */ |
| 103 | 105 | public function isSerialized() |
| 104 | 106 | { |
| 105 | - if ($this->getLength() === 0) return false; |
|
| 107 | + if ($this->getLength() === 0) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 106 | 110 | |
| 107 | 111 | /** @noinspection PhpUsageOfSilenceOperatorInspection */ |
| 108 | 112 | return |
@@ -120,7 +124,9 @@ discard block |
||
| 120 | 124 | public function isBase64() |
| 121 | 125 | { |
| 122 | 126 | // An empty string is by definition not encoded. |
| 123 | - if ($this->getLength() === 0) return false; |
|
| 127 | + if ($this->getLength() === 0) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 124 | 130 | |
| 125 | 131 | // Grab the current string value. |
| 126 | 132 | $possiblyEncoded = $this->scalarString; |
@@ -129,7 +135,9 @@ discard block |
||
| 129 | 135 | $decoded = base64_decode($possiblyEncoded, true); |
| 130 | 136 | |
| 131 | 137 | // If we get false it can't be base64 |
| 132 | - if ($decoded === false) return false; |
|
| 138 | + if ($decoded === false) { |
|
| 139 | + return false; |
|
| 140 | + } |
|
| 133 | 141 | |
| 134 | 142 | // Lets double check |
| 135 | 143 | return (base64_encode($decoded) === $this->scalarString); |
@@ -144,12 +144,12 @@ discard block |
||
| 144 | 144 | /** |
| 145 | 145 | * Factory method to create a new Gears\String\Str object. |
| 146 | 146 | * |
| 147 | - * @param mixed $string Must be a scalar string or an object |
|
| 147 | + * @param string $string Must be a scalar string or an object |
|
| 148 | 148 | * that implements the __toString() method |
| 149 | 149 | * or a value that is castable to a scalar |
| 150 | 150 | * string. |
| 151 | 151 | * |
| 152 | - * @param string $encoding The character encoding to use for this |
|
| 152 | + * @param string string The character encoding to use for this |
|
| 153 | 153 | * string. If not specified, defaults to |
| 154 | 154 | * the value returned from |
| 155 | 155 | * mb_internal_encoding(). |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | * |
| 273 | 273 | * @param mixed $offset The index from which to retrieve the char |
| 274 | 274 | * |
| 275 | - * @return string The character at the specified index |
|
| 275 | + * @return Base The character at the specified index |
|
| 276 | 276 | * @throws \OutOfBoundsException If the positive or negative offset does |
| 277 | 277 | * not exist |
| 278 | 278 | */ |
@@ -96,15 +96,13 @@ discard block |
||
| 96 | 96 | // Make sure we can use the provided string value as a string. |
| 97 | 97 | if (is_array($string)) |
| 98 | 98 | { |
| 99 | - throw new \InvalidArgumentException |
|
| 100 | - ( |
|
| 99 | + throw new \InvalidArgumentException( |
|
| 101 | 100 | 'Passed value cannot be an array' |
| 102 | 101 | ); |
| 103 | 102 | } |
| 104 | 103 | elseif (is_object($string) && !method_exists($string, '__toString')) |
| 105 | 104 | { |
| 106 | - throw new \InvalidArgumentException |
|
| 107 | - ( |
|
| 105 | + throw new \InvalidArgumentException( |
|
| 108 | 106 | 'Passed object must have a __toString method' |
| 109 | 107 | ); |
| 110 | 108 | } |
@@ -126,7 +124,7 @@ discard block |
||
| 126 | 124 | } |
| 127 | 125 | |
| 128 | 126 | // Set the strings length property. |
| 129 | - $this->stringLength = UTF8::strlen($this->scalarString,$this->encoding); |
|
| 127 | + $this->stringLength = UTF8::strlen($this->scalarString, $this->encoding); |
|
| 130 | 128 | } |
| 131 | 129 | |
| 132 | 130 | /** |
@@ -286,8 +284,7 @@ discard block |
||
| 286 | 284 | throw new \OutOfBoundsException('No character exists at the index'); |
| 287 | 285 | } |
| 288 | 286 | |
| 289 | - return $this->newSelf(UTF8::substr |
|
| 290 | - ( |
|
| 287 | + return $this->newSelf(UTF8::substr( |
|
| 291 | 288 | $this->scalarString, |
| 292 | 289 | $offset, |
| 293 | 290 | 1, |
@@ -100,8 +100,7 @@ discard block |
||
| 100 | 100 | ( |
| 101 | 101 | 'Passed value cannot be an array' |
| 102 | 102 | ); |
| 103 | - } |
|
| 104 | - elseif (is_object($string) && !method_exists($string, '__toString')) |
|
| 103 | + } elseif (is_object($string) && !method_exists($string, '__toString')) |
|
| 105 | 104 | { |
| 106 | 105 | throw new \InvalidArgumentException |
| 107 | 106 | ( |
@@ -119,8 +118,7 @@ discard block |
||
| 119 | 118 | if ($encoding !== null) |
| 120 | 119 | { |
| 121 | 120 | $this->encoding = $encoding; |
| 122 | - } |
|
| 123 | - else |
|
| 121 | + } else |
|
| 124 | 122 | { |
| 125 | 123 | $this->encoding = mb_internal_encoding(); |
| 126 | 124 | } |
@@ -199,13 +197,11 @@ discard block |
||
| 199 | 197 | { |
| 200 | 198 | // Convert the scalar string to a Str Object |
| 201 | 199 | $strObjects[$key] = $this->newSelf($value); |
| 202 | - } |
|
| 203 | - elseif (is_array($value)) |
|
| 200 | + } elseif (is_array($value)) |
|
| 204 | 201 | { |
| 205 | 202 | // Recurse into the array |
| 206 | 203 | $strObjects[$key] = $this->newSelfs($value); |
| 207 | - } |
|
| 208 | - else |
|
| 204 | + } else |
|
| 209 | 205 | { |
| 210 | 206 | // We don't know what it is do do nothing to it |
| 211 | 207 | $strObjects[$key] = $value; |
@@ -259,7 +255,9 @@ discard block |
||
| 259 | 255 | { |
| 260 | 256 | $index = (int)$index; |
| 261 | 257 | |
| 262 | - if ($index >= 0) return ($this->getLength() > $index); |
|
| 258 | + if ($index >= 0) { |
|
| 259 | + return ($this->getLength() > $index); |
|
| 260 | + } |
|
| 263 | 261 | |
| 264 | 262 | return ($this->getLength() >= abs($index)); |
| 265 | 263 | } |
@@ -26,10 +26,8 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | public function htmlDecode($flags = ENT_COMPAT) |
| 28 | 28 | { |
| 29 | - return $this->newSelf |
|
| 30 | - ( |
|
| 31 | - UTF8::html_entity_decode |
|
| 32 | - ( |
|
| 29 | + return $this->newSelf( |
|
| 30 | + UTF8::html_entity_decode( |
|
| 33 | 31 | $this->scalarString, |
| 34 | 32 | $flags, |
| 35 | 33 | $this->encoding |
@@ -54,10 +52,8 @@ discard block |
||
| 54 | 52 | { |
| 55 | 53 | if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
| 56 | 54 | |
| 57 | - return $this->newSelf |
|
| 58 | - ( |
|
| 59 | - UTF8::htmlentities |
|
| 60 | - ( |
|
| 55 | + return $this->newSelf( |
|
| 56 | + UTF8::htmlentities( |
|
| 61 | 57 | $this->scalarString, |
| 62 | 58 | $flags, |
| 63 | 59 | $this->encoding, |
@@ -97,8 +93,7 @@ discard block |
||
| 97 | 93 | } |
| 98 | 94 | else |
| 99 | 95 | { |
| 100 | - throw new \RuntimeException |
|
| 101 | - ( |
|
| 96 | + throw new \RuntimeException( |
|
| 102 | 97 | "This method requires \voku\helper\AntiXSS. ". |
| 103 | 98 | "Install with: composer require voku/anti-xss" |
| 104 | 99 | ); |
@@ -122,8 +117,7 @@ discard block |
||
| 122 | 117 | */ |
| 123 | 118 | public function htmlStripTags($allowableTags = null) |
| 124 | 119 | { |
| 125 | - return $this->newSelf |
|
| 126 | - ( |
|
| 120 | + return $this->newSelf( |
|
| 127 | 121 | UTF8::strip_tags($this->scalarString, $allowableTags) |
| 128 | 122 | ); |
| 129 | 123 | } |
@@ -52,7 +52,9 @@ discard block |
||
| 52 | 52 | */ |
| 53 | 53 | public function htmlEncode($flags = null, $doubleEncode = true) |
| 54 | 54 | { |
| 55 | - if ($flags === null) $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 55 | + if ($flags === null) { |
|
| 56 | + $flags = ENT_QUOTES | ENT_SUBSTITUTE; |
|
| 57 | + } |
|
| 56 | 58 | |
| 57 | 59 | return $this->newSelf |
| 58 | 60 | ( |
@@ -94,8 +96,7 @@ discard block |
||
| 94 | 96 | if (class_exists('\\voku\\helper\\AntiXSS')) |
| 95 | 97 | { |
| 96 | 98 | $antiXss = new \voku\helper\AntiXSS(); |
| 97 | - } |
|
| 98 | - else |
|
| 99 | + } else |
|
| 99 | 100 | { |
| 100 | 101 | throw new \RuntimeException |
| 101 | 102 | ( |
@@ -29,8 +29,7 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | public function indexOf($needle, $offset = 0) |
| 31 | 31 | { |
| 32 | - return UTF8::strpos |
|
| 33 | - ( |
|
| 32 | + return UTF8::strpos( |
|
| 34 | 33 | $this->scalarString, |
| 35 | 34 | (string)$needle, |
| 36 | 35 | (int)$offset, |
@@ -53,8 +52,7 @@ discard block |
||
| 53 | 52 | */ |
| 54 | 53 | public function indexOfLast($needle, $offset = 0) |
| 55 | 54 | { |
| 56 | - return UTF8::strrpos |
|
| 57 | - ( |
|
| 55 | + return UTF8::strrpos( |
|
| 58 | 56 | $this->scalarString, |
| 59 | 57 | (string)$needle, |
| 60 | 58 | (int)$offset, |