| @@ -36,20 +36,20 @@ | ||
| 36 | 36 | public const PREG_SPLIT_DELIM_CAPTURE = \PREG_SPLIT_DELIM_CAPTURE; |
| 37 | 37 | public const PREG_SPLIT_OFFSET_CAPTURE = \PREG_SPLIT_OFFSET_CAPTURE; |
| 38 | 38 | protected $string = ''; |
| 39 | 39 | protected $ignoreCase = \false; |
| 40 | - public abstract function __construct(string $string = ''); | |
| 40 | + abstract public function __construct(string $string = ''); | |
| 41 | 41 | /** |
| 42 | 42 | * Unwraps instances of AbstractString back to strings. |
| 43 | 43 | * |
| 44 | 44 | * @return string[]|array |
| 45 | 45 | */ |
| 46 | - public static function unwrap(array $values) : array | |
| 46 | + public static function unwrap(array $values): array | |
| 47 | 47 | { |
| 48 | 48 | foreach ($values as $k => $v) { |
| 49 | 49 | if ($v instanceof self) { |
| 50 | 50 | $values[$k] = $v->__toString(); |
| 51 | - } elseif (\is_array($v) && $values[$k] !== ($v = static::unwrap($v))) { | |
| 51 | + } elseif (\is_array($v) && $values[$k] !== $v = static::unwrap($v)) { | |
| 52 | 52 | $values[$k] = $v; |
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | return $values; |
| @@ -58,25 +58,25 @@ | ||
| 58 | 58 | * Wraps (and normalizes) strings in instances of AbstractString. |
| 59 | 59 | * |
| 60 | 60 | * @return static[]|array |
| 61 | 61 | */ |
| 62 | - public static function wrap(array $values) : array | |
| 62 | + public static function wrap(array $values): array | |
| 63 | 63 | { |
| 64 | 64 | $i = 0; |
| 65 | 65 | $keys = null; |
| 66 | 66 | foreach ($values as $k => $v) { |
| 67 | - if (\is_string($k) && '' !== $k && $k !== ($j = (string) new static($k))) { | |
| 68 | - $keys = $keys ?? \array_keys($values); | |
| 67 | + if (\is_string($k) && '' !== $k && $k !== $j = (string) new static($k)) { | |
| 68 | + $keys = $keys ?? array_keys($values); | |
| 69 | 69 | $keys[$i] = $j; |
| 70 | 70 | } |
| 71 | 71 | if (\is_string($v)) { |
| 72 | 72 | $values[$k] = new static($v); |
| 73 | - } elseif (\is_array($v) && $values[$k] !== ($v = static::wrap($v))) { | |
| 73 | + } elseif (\is_array($v) && $values[$k] !== $v = static::wrap($v)) { | |
| 74 | 74 | $values[$k] = $v; |
| 75 | 75 | } |
| 76 | 76 | ++$i; |
| 77 | 77 | } |
| 78 | - return null !== $keys ? \array_combine($keys, $values) : $values; | |
| 78 | + return null !== $keys ? array_combine($keys, $values) : $values; | |
| 79 | 79 | } |
| 80 | 80 | /** |
| 81 | 81 | * @param string|string[] $needle |
| 82 | 82 | * |
| @@ -81,9 +81,9 @@ | ||
| 81 | 81 | * @param string|string[] $needle |
| 82 | 82 | * |
| 83 | 83 | * @return static |
| 84 | 84 | */ |
| 85 | - public function after($needle, bool $includeNeedle = \false, int $offset = 0) : self | |
| 85 | + public function after($needle, bool $includeNeedle = \false, int $offset = 0): self | |
| 86 | 86 | { |
| 87 | 87 | $str = clone $this; |
| 88 | 88 | $i = \PHP_INT_MAX; |
| 89 | 89 | foreach ((array) $needle as $n) { |
| @@ -106,9 +106,9 @@ | ||
| 106 | 106 | * @param string|string[] $needle |
| 107 | 107 | * |
| 108 | 108 | * @return static |
| 109 | 109 | */ |
| 110 | - public function afterLast($needle, bool $includeNeedle = \false, int $offset = 0) : self | |
| 110 | + public function afterLast($needle, bool $includeNeedle = \false, int $offset = 0): self | |
| 111 | 111 | { |
| 112 | 112 | $str = clone $this; |
| 113 | 113 | $i = null; |
| 114 | 114 | foreach ((array) $needle as $n) { |
| @@ -129,15 +129,15 @@ | ||
| 129 | 129 | } |
| 130 | 130 | /** |
| 131 | 131 | * @return static |
| 132 | 132 | */ |
| 133 | - public abstract function append(string ...$suffix) : self; | |
| 133 | + abstract public function append(string ...$suffix): self; | |
| 134 | 134 | /** |
| 135 | 135 | * @param string|string[] $needle |
| 136 | 136 | * |
| 137 | 137 | * @return static |
| 138 | 138 | */ |
| 139 | - public function before($needle, bool $includeNeedle = \false, int $offset = 0) : self | |
| 139 | + public function before($needle, bool $includeNeedle = \false, int $offset = 0): self | |
| 140 | 140 | { |
| 141 | 141 | $str = clone $this; |
| 142 | 142 | $i = \PHP_INT_MAX; |
| 143 | 143 | foreach ((array) $needle as $n) { |
| @@ -160,9 +160,9 @@ | ||
| 160 | 160 | * @param string|string[] $needle |
| 161 | 161 | * |
| 162 | 162 | * @return static |
| 163 | 163 | */ |
| 164 | - public function beforeLast($needle, bool $includeNeedle = \false, int $offset = 0) : self | |
| 164 | + public function beforeLast($needle, bool $includeNeedle = \false, int $offset = 0): self | |
| 165 | 165 | { |
| 166 | 166 | $str = clone $this; |
| 167 | 167 | $i = null; |
| 168 | 168 | foreach ((array) $needle as $n) { |
| @@ -183,34 +183,34 @@ | ||
| 183 | 183 | } |
| 184 | 184 | /** |
| 185 | 185 | * @return int[] |
| 186 | 186 | */ |
| 187 | - public function bytesAt(int $offset) : array | |
| 187 | + public function bytesAt(int $offset): array | |
| 188 | 188 | { |
| 189 | 189 | $str = $this->slice($offset, 1); |
| 190 | - return '' === $str->string ? [] : \array_values(\unpack('C*', $str->string)); | |
| 190 | + return '' === $str->string ? [] : array_values(unpack('C*', $str->string)); | |
| 191 | 191 | } |
| 192 | 192 | /** |
| 193 | 193 | * @return static |
| 194 | 194 | */ |
| 195 | - public abstract function camel() : self; | |
| 195 | + abstract public function camel(): self; | |
| 196 | 196 | /** |
| 197 | 197 | * @return static[] |
| 198 | 198 | */ |
| 199 | - public abstract function chunk(int $length = 1) : array; | |
| 199 | + abstract public function chunk(int $length = 1): array; | |
| 200 | 200 | /** |
| 201 | 201 | * @return static |
| 202 | 202 | */ |
| 203 | - public function collapseWhitespace() : self | |
| 203 | + public function collapseWhitespace(): self | |
| 204 | 204 | { |
| 205 | 205 | $str = clone $this; |
| 206 | - $str->string = \trim(\preg_replace("/(?:[ \n\r\t\f]{2,}+|[\n\r\t\f])/", ' ', $str->string), " \n\r\t\f"); | |
| 206 | + $str->string = trim(preg_replace("/(?:[ \n\r\t\f]{2,}+|[\n\r\t\f])/", ' ', $str->string), " \n\r\t\f"); | |
| 207 | 207 | return $str; |
| 208 | 208 | } |
| 209 | 209 | /** |
| 210 | 210 | * @param string|string[] $needle |
| 211 | 211 | */ |
| 212 | - public function containsAny($needle) : bool | |
| 212 | + public function containsAny($needle): bool | |
| 213 | 213 | { |
| 214 | 214 | return null !== $this->indexOf($needle); |
| 215 | 215 | } |
| 216 | 216 | /** |
| @@ -215,12 +215,12 @@ | ||
| 215 | 215 | } |
| 216 | 216 | /** |
| 217 | 217 | * @param string|string[] $suffix |
| 218 | 218 | */ |
| 219 | - public function endsWith($suffix) : bool | |
| 219 | + public function endsWith($suffix): bool | |
| 220 | 220 | { |
| 221 | 221 | if (!\is_array($suffix) && !$suffix instanceof \Traversable) { |
| 222 | - throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 222 | + throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 223 | 223 | } |
| 224 | 224 | foreach ($suffix as $s) { |
| 225 | 225 | if ($this->endsWith((string) $s)) { |
| 226 | 226 | return \true; |
| @@ -230,14 +230,14 @@ | ||
| 230 | 230 | } |
| 231 | 231 | /** |
| 232 | 232 | * @return static |
| 233 | 233 | */ |
| 234 | - public function ensureEnd(string $suffix) : self | |
| 234 | + public function ensureEnd(string $suffix): self | |
| 235 | 235 | { |
| 236 | 236 | if (!$this->endsWith($suffix)) { |
| 237 | 237 | return $this->append($suffix); |
| 238 | 238 | } |
| 239 | - $suffix = \preg_quote($suffix); | |
| 239 | + $suffix = preg_quote($suffix); | |
| 240 | 240 | $regex = '{(' . $suffix . ')(?:' . $suffix . ')++$}D'; |
| 241 | 241 | return $this->replaceMatches($regex . ($this->ignoreCase ? 'i' : ''), '$1'); |
| 242 | 242 | } |
| 243 | 243 | /** |
| @@ -242,9 +242,9 @@ | ||
| 242 | 242 | } |
| 243 | 243 | /** |
| 244 | 244 | * @return static |
| 245 | 245 | */ |
| 246 | - public function ensureStart(string $prefix) : self | |
| 246 | + public function ensureStart(string $prefix): self | |
| 247 | 247 | { |
| 248 | 248 | $prefix = new static($prefix); |
| 249 | 249 | if (!$this->startsWith($prefix)) { |
| 250 | 250 | return $this->prepend($prefix); |
| @@ -259,12 +259,12 @@ | ||
| 259 | 259 | } |
| 260 | 260 | /** |
| 261 | 261 | * @param string|string[] $string |
| 262 | 262 | */ |
| 263 | - public function equalsTo($string) : bool | |
| 263 | + public function equalsTo($string): bool | |
| 264 | 264 | { |
| 265 | 265 | if (!\is_array($string) && !$string instanceof \Traversable) { |
| 266 | - throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 266 | + throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 267 | 267 | } |
| 268 | 268 | foreach ($string as $s) { |
| 269 | 269 | if ($this->equalsTo((string) $s)) { |
| 270 | 270 | return \true; |
| @@ -274,13 +274,13 @@ | ||
| 274 | 274 | } |
| 275 | 275 | /** |
| 276 | 276 | * @return static |
| 277 | 277 | */ |
| 278 | - public abstract function folded() : self; | |
| 278 | + abstract public function folded(): self; | |
| 279 | 279 | /** |
| 280 | 280 | * @return static |
| 281 | 281 | */ |
| 282 | - public function ignoreCase() : self | |
| 282 | + public function ignoreCase(): self | |
| 283 | 283 | { |
| 284 | 284 | $str = clone $this; |
| 285 | 285 | $str->ignoreCase = \true; |
| 286 | 286 | return $str; |
| @@ -287,12 +287,12 @@ | ||
| 287 | 287 | } |
| 288 | 288 | /** |
| 289 | 289 | * @param string|string[] $needle |
| 290 | 290 | */ |
| 291 | - public function indexOf($needle, int $offset = 0) : ?int | |
| 291 | + public function indexOf($needle, int $offset = 0): ?int | |
| 292 | 292 | { |
| 293 | 293 | if (!\is_array($needle) && !$needle instanceof \Traversable) { |
| 294 | - throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 294 | + throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 295 | 295 | } |
| 296 | 296 | $i = \PHP_INT_MAX; |
| 297 | 297 | foreach ($needle as $n) { |
| 298 | 298 | $j = $this->indexOf((string) $n, $offset); |
| @@ -304,12 +304,12 @@ | ||
| 304 | 304 | } |
| 305 | 305 | /** |
| 306 | 306 | * @param string|string[] $needle |
| 307 | 307 | */ |
| 308 | - public function indexOfLast($needle, int $offset = 0) : ?int | |
| 308 | + public function indexOfLast($needle, int $offset = 0): ?int | |
| 309 | 309 | { |
| 310 | 310 | if (!\is_array($needle) && !$needle instanceof \Traversable) { |
| 311 | - throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 311 | + throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 312 | 312 | } |
| 313 | 313 | $i = null; |
| 314 | 314 | foreach ($needle as $n) { |
| 315 | 315 | $j = $this->indexOfLast((string) $n, $offset); |
| @@ -318,9 +318,9 @@ | ||
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | return $i; |
| 321 | 321 | } |
| 322 | - public function isEmpty() : bool | |
| 322 | + public function isEmpty(): bool | |
| 323 | 323 | { |
| 324 | 324 | return '' === $this->string; |
| 325 | 325 | } |
| 326 | 326 | /** |
| @@ -325,18 +325,18 @@ | ||
| 325 | 325 | } |
| 326 | 326 | /** |
| 327 | 327 | * @return static |
| 328 | 328 | */ |
| 329 | - public abstract function join(array $strings, ?string $lastGlue = null) : self; | |
| 330 | - public function jsonSerialize() : string | |
| 329 | + abstract public function join(array $strings, ?string $lastGlue = null): self; | |
| 330 | + public function jsonSerialize(): string | |
| 331 | 331 | { |
| 332 | 332 | return $this->string; |
| 333 | 333 | } |
| 334 | - public abstract function length() : int; | |
| 334 | + abstract public function length(): int; | |
| 335 | 335 | /** |
| 336 | 336 | * @return static |
| 337 | 337 | */ |
| 338 | - public abstract function lower() : self; | |
| 338 | + abstract public function lower(): self; | |
| 339 | 339 | /** |
| 340 | 340 | * Matches the string using a regular expression. |
| 341 | 341 | * |
| 342 | 342 | * Pass PREG_PATTERN_ORDER or PREG_SET_ORDER as $flags to get all occurrences matching the regular expression. |
| @@ -342,67 +342,67 @@ | ||
| 342 | 342 | * Pass PREG_PATTERN_ORDER or PREG_SET_ORDER as $flags to get all occurrences matching the regular expression. |
| 343 | 343 | * |
| 344 | 344 | * @return array All matches in a multi-dimensional array ordered according to flags |
| 345 | 345 | */ |
| 346 | - public abstract function match(string $regexp, int $flags = 0, int $offset = 0) : array; | |
| 346 | + abstract public function match(string $regexp, int $flags = 0, int $offset = 0): array; | |
| 347 | 347 | /** |
| 348 | 348 | * @return static |
| 349 | 349 | */ |
| 350 | - public abstract function padBoth(int $length, string $padStr = ' ') : self; | |
| 350 | + abstract public function padBoth(int $length, string $padStr = ' '): self; | |
| 351 | 351 | /** |
| 352 | 352 | * @return static |
| 353 | 353 | */ |
| 354 | - public abstract function padEnd(int $length, string $padStr = ' ') : self; | |
| 354 | + abstract public function padEnd(int $length, string $padStr = ' '): self; | |
| 355 | 355 | /** |
| 356 | 356 | * @return static |
| 357 | 357 | */ |
| 358 | - public abstract function padStart(int $length, string $padStr = ' ') : self; | |
| 358 | + abstract public function padStart(int $length, string $padStr = ' '): self; | |
| 359 | 359 | /** |
| 360 | 360 | * @return static |
| 361 | 361 | */ |
| 362 | - public abstract function prepend(string ...$prefix) : self; | |
| 362 | + abstract public function prepend(string ...$prefix): self; | |
| 363 | 363 | /** |
| 364 | 364 | * @return static |
| 365 | 365 | */ |
| 366 | - public function repeat(int $multiplier) : self | |
| 366 | + public function repeat(int $multiplier): self | |
| 367 | 367 | { |
| 368 | 368 | if (0 > $multiplier) { |
| 369 | - throw new InvalidArgumentException(\sprintf('Multiplier must be positive, %d given.', $multiplier)); | |
| 369 | + throw new InvalidArgumentException(sprintf('Multiplier must be positive, %d given.', $multiplier)); | |
| 370 | 370 | } |
| 371 | 371 | $str = clone $this; |
| 372 | - $str->string = \str_repeat($str->string, $multiplier); | |
| 372 | + $str->string = str_repeat($str->string, $multiplier); | |
| 373 | 373 | return $str; |
| 374 | 374 | } |
| 375 | 375 | /** |
| 376 | 376 | * @return static |
| 377 | 377 | */ |
| 378 | - public abstract function replace(string $from, string $to) : self; | |
| 378 | + abstract public function replace(string $from, string $to): self; | |
| 379 | 379 | /** |
| 380 | 380 | * @param string|callable $to |
| 381 | 381 | * |
| 382 | 382 | * @return static |
| 383 | 383 | */ |
| 384 | - public abstract function replaceMatches(string $fromRegexp, $to) : self; | |
| 384 | + abstract public function replaceMatches(string $fromRegexp, $to): self; | |
| 385 | 385 | /** |
| 386 | 386 | * @return static |
| 387 | 387 | */ |
| 388 | - public abstract function reverse() : self; | |
| 388 | + abstract public function reverse(): self; | |
| 389 | 389 | /** |
| 390 | 390 | * @return static |
| 391 | 391 | */ |
| 392 | - public abstract function slice(int $start = 0, ?int $length = null) : self; | |
| 392 | + abstract public function slice(int $start = 0, ?int $length = null): self; | |
| 393 | 393 | /** |
| 394 | 394 | * @return static |
| 395 | 395 | */ |
| 396 | - public abstract function snake() : self; | |
| 396 | + abstract public function snake(): self; | |
| 397 | 397 | /** |
| 398 | 398 | * @return static |
| 399 | 399 | */ |
| 400 | - public abstract function splice(string $replacement, int $start = 0, ?int $length = null) : self; | |
| 400 | + abstract public function splice(string $replacement, int $start = 0, ?int $length = null): self; | |
| 401 | 401 | /** |
| 402 | 402 | * @return static[] |
| 403 | 403 | */ |
| 404 | - public function split(string $delimiter, ?int $limit = null, ?int $flags = null) : array | |
| 404 | + public function split(string $delimiter, ?int $limit = null, ?int $flags = null): array | |
| 405 | 405 | { |
| 406 | 406 | if (null === $flags) { |
| 407 | 407 | throw new \TypeError('Split behavior when $flags is null must be implemented by child classes.'); |
| 408 | 408 | } |
| @@ -408,16 +408,16 @@ | ||
| 408 | 408 | } |
| 409 | 409 | if ($this->ignoreCase) { |
| 410 | 410 | $delimiter .= 'i'; |
| 411 | 411 | } |
| 412 | - \set_error_handler(static function ($t, $m) { | |
| 412 | + set_error_handler(static function ($t, $m) { | |
| 413 | 413 | throw new InvalidArgumentException($m); |
| 414 | 414 | }); |
| 415 | 415 | try { |
| 416 | - if (\false === ($chunks = \preg_split($delimiter, $this->string, $limit, $flags))) { | |
| 417 | - $lastError = \preg_last_error(); | |
| 418 | - foreach (\get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 419 | - if ($lastError === $v && '_ERROR' === \substr($k, -6)) { | |
| 416 | + if (\false === $chunks = preg_split($delimiter, $this->string, $limit, $flags)) { | |
| 417 | + $lastError = preg_last_error(); | |
| 418 | + foreach (get_defined_constants(\true)['pcre'] as $k => $v) { | |
| 419 | + if ($lastError === $v && '_ERROR' === substr($k, -6)) { | |
| 420 | 420 | throw new RuntimeException('Splitting failed with ' . $k . '.'); |
| 421 | 421 | } |
| 422 | 422 | } |
| 423 | 423 | throw new RuntimeException('Splitting failed with unknown error code.'); |
| @@ -422,9 +422,9 @@ | ||
| 422 | 422 | } |
| 423 | 423 | throw new RuntimeException('Splitting failed with unknown error code.'); |
| 424 | 424 | } |
| 425 | 425 | } finally { |
| 426 | - \restore_error_handler(); | |
| 426 | + restore_error_handler(); | |
| 427 | 427 | } |
| 428 | 428 | $str = clone $this; |
| 429 | 429 | if (self::PREG_SPLIT_OFFSET_CAPTURE & $flags) { |
| 430 | 430 | foreach ($chunks as &$chunk) { |
| @@ -441,12 +441,12 @@ | ||
| 441 | 441 | } |
| 442 | 442 | /** |
| 443 | 443 | * @param string|string[] $prefix |
| 444 | 444 | */ |
| 445 | - public function startsWith($prefix) : bool | |
| 445 | + public function startsWith($prefix): bool | |
| 446 | 446 | { |
| 447 | 447 | if (!\is_array($prefix) && !$prefix instanceof \Traversable) { |
| 448 | - throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 448 | + throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); | |
| 449 | 449 | } |
| 450 | 450 | foreach ($prefix as $prefix) { |
| 451 | 451 | if ($this->startsWith((string) $prefix)) { |
| 452 | 452 | return \true; |
| @@ -456,46 +456,46 @@ | ||
| 456 | 456 | } |
| 457 | 457 | /** |
| 458 | 458 | * @return static |
| 459 | 459 | */ |
| 460 | - public abstract function title(bool $allWords = \false) : self; | |
| 461 | - public function toByteString(?string $toEncoding = null) : ByteString | |
| 460 | + abstract public function title(bool $allWords = \false): self; | |
| 461 | + public function toByteString(?string $toEncoding = null): ByteString | |
| 462 | 462 | { |
| 463 | 463 | $b = new ByteString(); |
| 464 | 464 | $toEncoding = \in_array($toEncoding, ['utf8', 'utf-8', 'UTF8'], \true) ? 'UTF-8' : $toEncoding; |
| 465 | - if (null === $toEncoding || $toEncoding === ($fromEncoding = $this instanceof AbstractUnicodeString || \preg_match('//u', $b->string) ? 'UTF-8' : 'Windows-1252')) { | |
| 465 | + if (null === $toEncoding || $toEncoding === $fromEncoding = $this instanceof AbstractUnicodeString || preg_match('//u', $b->string) ? 'UTF-8' : 'Windows-1252') { | |
| 466 | 466 | $b->string = $this->string; |
| 467 | 467 | return $b; |
| 468 | 468 | } |
| 469 | - \set_error_handler(static function ($t, $m) { | |
| 469 | + set_error_handler(static function ($t, $m) { | |
| 470 | 470 | throw new InvalidArgumentException($m); |
| 471 | 471 | }); |
| 472 | 472 | try { |
| 473 | 473 | try { |
| 474 | - $b->string = \mb_convert_encoding($this->string, $toEncoding, 'UTF-8'); | |
| 474 | + $b->string = mb_convert_encoding($this->string, $toEncoding, 'UTF-8'); | |
| 475 | 475 | } catch (InvalidArgumentException|\ValueError $e) { |
| 476 | - if (!\function_exists('iconv')) { | |
| 476 | + if (!\function_exists('iconv') && !\function_exists('WindPressDeps\iconv')) { | |
| 477 | 477 | if ($e instanceof \ValueError) { |
| 478 | 478 | throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e); |
| 479 | 479 | } |
| 480 | 480 | throw $e; |
| 481 | 481 | } |
| 482 | - $b->string = \iconv('UTF-8', $toEncoding, $this->string); | |
| 482 | + $b->string = iconv('UTF-8', $toEncoding, $this->string); | |
| 483 | 483 | } |
| 484 | 484 | } finally { |
| 485 | - \restore_error_handler(); | |
| 485 | + restore_error_handler(); | |
| 486 | 486 | } |
| 487 | 487 | return $b; |
| 488 | 488 | } |
| 489 | - public function toCodePointString() : CodePointString | |
| 489 | + public function toCodePointString(): CodePointString | |
| 490 | 490 | { |
| 491 | 491 | return new CodePointString($this->string); |
| 492 | 492 | } |
| 493 | - public function toString() : string | |
| 493 | + public function toString(): string | |
| 494 | 494 | { |
| 495 | 495 | return $this->string; |
| 496 | 496 | } |
| 497 | - public function toUnicodeString() : UnicodeString | |
| 497 | + public function toUnicodeString(): UnicodeString | |
| 498 | 498 | { |
| 499 | 499 | return new UnicodeString($this->string); |
| 500 | 500 | } |
| 501 | 501 | /** |
| @@ -500,19 +500,19 @@ | ||
| 500 | 500 | } |
| 501 | 501 | /** |
| 502 | 502 | * @return static |
| 503 | 503 | */ |
| 504 | - public abstract function trim(string $chars = " \t\n\r\x00\v\f ") : self; | |
| 504 | + abstract public function trim(string $chars = " \t\n\r\x00\v\f "): self; | |
| 505 | 505 | /** |
| 506 | 506 | * @return static |
| 507 | 507 | */ |
| 508 | - public abstract function trimEnd(string $chars = " \t\n\r\x00\v\f ") : self; | |
| 508 | + abstract public function trimEnd(string $chars = " \t\n\r\x00\v\f "): self; | |
| 509 | 509 | /** |
| 510 | 510 | * @param string|string[] $prefix |
| 511 | 511 | * |
| 512 | 512 | * @return static |
| 513 | 513 | */ |
| 514 | - public function trimPrefix($prefix) : self | |
| 514 | + public function trimPrefix($prefix): self | |
| 515 | 515 | { |
| 516 | 516 | if (\is_array($prefix) || $prefix instanceof \Traversable) { |
| 517 | 517 | foreach ($prefix as $s) { |
| 518 | 518 | $t = $this->trimPrefix($s); |
| @@ -527,10 +527,10 @@ | ||
| 527 | 527 | $prefix = $prefix->string; |
| 528 | 528 | } else { |
| 529 | 529 | $prefix = (string) $prefix; |
| 530 | 530 | } |
| 531 | - if ('' !== $prefix && \strlen($this->string) >= \strlen($prefix) && 0 === \substr_compare($this->string, $prefix, 0, \strlen($prefix), $this->ignoreCase)) { | |
| 532 | - $str->string = \substr($this->string, \strlen($prefix)); | |
| 531 | + if ('' !== $prefix && \strlen($this->string) >= \strlen($prefix) && 0 === substr_compare($this->string, $prefix, 0, \strlen($prefix), $this->ignoreCase)) { | |
| 532 | + $str->string = substr($this->string, \strlen($prefix)); | |
| 533 | 533 | } |
| 534 | 534 | return $str; |
| 535 | 535 | } |
| 536 | 536 | /** |
| @@ -535,15 +535,15 @@ | ||
| 535 | 535 | } |
| 536 | 536 | /** |
| 537 | 537 | * @return static |
| 538 | 538 | */ |
| 539 | - public abstract function trimStart(string $chars = " \t\n\r\x00\v\f ") : self; | |
| 539 | + abstract public function trimStart(string $chars = " \t\n\r\x00\v\f "): self; | |
| 540 | 540 | /** |
| 541 | 541 | * @param string|string[] $suffix |
| 542 | 542 | * |
| 543 | 543 | * @return static |
| 544 | 544 | */ |
| 545 | - public function trimSuffix($suffix) : self | |
| 545 | + public function trimSuffix($suffix): self | |
| 546 | 546 | { |
| 547 | 547 | if (\is_array($suffix) || $suffix instanceof \Traversable) { |
| 548 | 548 | foreach ($suffix as $s) { |
| 549 | 549 | $t = $this->trimSuffix($s); |
| @@ -558,10 +558,10 @@ | ||
| 558 | 558 | $suffix = $suffix->string; |
| 559 | 559 | } else { |
| 560 | 560 | $suffix = (string) $suffix; |
| 561 | 561 | } |
| 562 | - if ('' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === \substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase)) { | |
| 563 | - $str->string = \substr($this->string, 0, -\strlen($suffix)); | |
| 562 | + if ('' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase)) { | |
| 563 | + $str->string = substr($this->string, 0, -\strlen($suffix)); | |
| 564 | 564 | } |
| 565 | 565 | return $str; |
| 566 | 566 | } |
| 567 | 567 | /** |
| @@ -566,9 +566,9 @@ | ||
| 566 | 566 | } |
| 567 | 567 | /** |
| 568 | 568 | * @return static |
| 569 | 569 | */ |
| 570 | - public function truncate(int $length, string $ellipsis = '', bool $cut = \true) : self | |
| 570 | + public function truncate(int $length, string $ellipsis = '', bool $cut = \true): self | |
| 571 | 571 | { |
| 572 | 572 | $stringLength = $this->length(); |
| 573 | 573 | if ($stringLength <= $length) { |
| 574 | 574 | return clone $this; |
| @@ -577,9 +577,9 @@ | ||
| 577 | 577 | if ($length < $ellipsisLength) { |
| 578 | 578 | $ellipsisLength = 0; |
| 579 | 579 | } |
| 580 | 580 | if (!$cut) { |
| 581 | - if (null === ($length = $this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1))) { | |
| 581 | + if (null === $length = $this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1)) { | |
| 582 | 582 | return clone $this; |
| 583 | 583 | } |
| 584 | 584 | $length += $ellipsisLength; |
| 585 | 585 | } |
| @@ -588,17 +588,17 @@ | ||
| 588 | 588 | } |
| 589 | 589 | /** |
| 590 | 590 | * @return static |
| 591 | 591 | */ |
| 592 | - public abstract function upper() : self; | |
| 592 | + abstract public function upper(): self; | |
| 593 | 593 | /** |
| 594 | 594 | * Returns the printable length on a terminal. |
| 595 | 595 | */ |
| 596 | - public abstract function width(bool $ignoreAnsiDecoration = \true) : int; | |
| 596 | + abstract public function width(bool $ignoreAnsiDecoration = \true): int; | |
| 597 | 597 | /** |
| 598 | 598 | * @return static |
| 599 | 599 | */ |
| 600 | - public function wordwrap(int $width = 75, string $break = "\n", bool $cut = \false) : self | |
| 600 | + public function wordwrap(int $width = 75, string $break = "\n", bool $cut = \false): self | |
| 601 | 601 | { |
| 602 | 602 | $lines = '' !== $break ? $this->split($break) : [clone $this]; |
| 603 | 603 | $chars = []; |
| 604 | 604 | $mask = ''; |
| @@ -617,10 +617,10 @@ | ||
| 617 | 617 | } |
| 618 | 618 | $string = ''; |
| 619 | 619 | $j = 0; |
| 620 | 620 | $b = $i = -1; |
| 621 | - $mask = \wordwrap($mask, $width, '#', $cut); | |
| 622 | - while (\false !== ($b = \strpos($mask, '#', $b + 1))) { | |
| 621 | + $mask = wordwrap($mask, $width, '#', $cut); | |
| 622 | + while (\false !== $b = strpos($mask, '#', $b + 1)) { | |
| 623 | 623 | for (++$i; $i < $b; ++$i) { |
| 624 | 624 | $string .= $chars[$j]; |
| 625 | 625 | unset($chars[$j++]); |
| 626 | 626 | } |
| @@ -629,12 +629,12 @@ | ||
| 629 | 629 | } |
| 630 | 630 | $string .= $break; |
| 631 | 631 | } |
| 632 | 632 | $str = clone $this; |
| 633 | - $str->string = $string . \implode('', $chars); | |
| 633 | + $str->string = $string . implode('', $chars); | |
| 634 | 634 | return $str; |
| 635 | 635 | } |
| 636 | - public function __sleep() : array | |
| 636 | + public function __sleep(): array | |
| 637 | 637 | { |
| 638 | 638 | return ['string']; |
| 639 | 639 | } |
| 640 | 640 | public function __clone() |
| @@ -640,9 +640,9 @@ | ||
| 640 | 640 | public function __clone() |
| 641 | 641 | { |
| 642 | 642 | $this->ignoreCase = \false; |
| 643 | 643 | } |
| 644 | - public function __toString() : string | |
| 644 | + public function __toString(): string | |
| 645 | 645 | { |
| 646 | 646 | return $this->string; |
| 647 | 647 | } |
| 648 | 648 | } |