@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | /** |
| 94 | 94 | * @param string|string[] $needle |
| 95 | 95 | */ |
| 96 | - public function after(string|iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 96 | + public function after(string | iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 97 | 97 | { |
| 98 | 98 | $str = clone $this; |
| 99 | 99 | $i = \PHP_INT_MAX; |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | /** |
| 127 | 127 | * @param string|string[] $needle |
| 128 | 128 | */ |
| 129 | - public function afterLast(string|iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 129 | + public function afterLast(string | iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 130 | 130 | { |
| 131 | 131 | $str = clone $this; |
| 132 | 132 | $i = null; |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | /** |
| 162 | 162 | * @param string|string[] $needle |
| 163 | 163 | */ |
| 164 | - public function before(string|iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 164 | + public function before(string | iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 165 | 165 | { |
| 166 | 166 | $str = clone $this; |
| 167 | 167 | $i = \PHP_INT_MAX; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | /** |
| 195 | 195 | * @param string|string[] $needle |
| 196 | 196 | */ |
| 197 | - public function beforeLast(string|iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 197 | + public function beforeLast(string | iterable $needle, bool $includeNeedle = false, int $offset = 0): static |
|
| 198 | 198 | { |
| 199 | 199 | $str = clone $this; |
| 200 | 200 | $i = null; |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | /** |
| 253 | 253 | * @param string|string[] $needle |
| 254 | 254 | */ |
| 255 | - public function containsAny(string|iterable $needle): bool |
|
| 255 | + public function containsAny(string | iterable $needle): bool |
|
| 256 | 256 | { |
| 257 | 257 | return null !== $this->indexOf($needle); |
| 258 | 258 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | /** |
| 261 | 261 | * @param string|string[] $suffix |
| 262 | 262 | */ |
| 263 | - public function endsWith(string|iterable $suffix): bool |
|
| 263 | + public function endsWith(string | iterable $suffix): bool |
|
| 264 | 264 | { |
| 265 | 265 | if (\is_string($suffix)) { |
| 266 | 266 | throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); |
@@ -282,9 +282,9 @@ discard block |
||
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | $suffix = preg_quote($suffix); |
| 285 | - $regex = '{('.$suffix.')(?:'.$suffix.')++$}D'; |
|
| 285 | + $regex = '{(' . $suffix . ')(?:' . $suffix . ')++$}D'; |
|
| 286 | 286 | |
| 287 | - return $this->replaceMatches($regex.($this->ignoreCase ? 'i' : ''), '$1'); |
|
| 287 | + return $this->replaceMatches($regex . ($this->ignoreCase ? 'i' : ''), '$1'); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | public function ensureStart(string $prefix): static |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | /** |
| 310 | 310 | * @param string|string[] $string |
| 311 | 311 | */ |
| 312 | - public function equalsTo(string|iterable $string): bool |
|
| 312 | + public function equalsTo(string | iterable $string): bool |
|
| 313 | 313 | { |
| 314 | 314 | if (\is_string($string)) { |
| 315 | 315 | throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | /** |
| 338 | 338 | * @param string|string[] $needle |
| 339 | 339 | */ |
| 340 | - public function indexOf(string|iterable $needle, int $offset = 0): ?int |
|
| 340 | + public function indexOf(string | iterable $needle, int $offset = 0): ?int |
|
| 341 | 341 | { |
| 342 | 342 | if (\is_string($needle)) { |
| 343 | 343 | throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | /** |
| 360 | 360 | * @param string|string[] $needle |
| 361 | 361 | */ |
| 362 | - public function indexOfLast(string|iterable $needle, int $offset = 0): ?int |
|
| 362 | + public function indexOfLast(string | iterable $needle, int $offset = 0): ?int |
|
| 363 | 363 | { |
| 364 | 364 | if (\is_string($needle)) { |
| 365 | 365 | throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | |
| 426 | 426 | abstract public function replace(string $from, string $to): static; |
| 427 | 427 | |
| 428 | - abstract public function replaceMatches(string $fromRegexp, string|callable $to): static; |
|
| 428 | + abstract public function replaceMatches(string $fromRegexp, string | callable $to): static; |
|
| 429 | 429 | |
| 430 | 430 | abstract public function reverse(): static; |
| 431 | 431 | |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | |
| 453 | 453 | try { |
| 454 | 454 | if (false === $chunks = preg_split($delimiter, $this->string, $limit, $flags)) { |
| 455 | - throw new RuntimeException('Splitting failed with error: '.preg_last_error_msg()); |
|
| 455 | + throw new RuntimeException('Splitting failed with error: ' . preg_last_error_msg()); |
|
| 456 | 456 | } |
| 457 | 457 | } finally { |
| 458 | 458 | restore_error_handler(); |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | /** |
| 479 | 479 | * @param string|string[] $prefix |
| 480 | 480 | */ |
| 481 | - public function startsWith(string|iterable $prefix): bool |
|
| 481 | + public function startsWith(string | iterable $prefix): bool |
|
| 482 | 482 | { |
| 483 | 483 | if (\is_string($prefix)) { |
| 484 | 484 | throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class)); |
@@ -680,7 +680,7 @@ discard block |
||
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | $str = clone $this; |
| 683 | - $str->string = $string.implode('', $chars); |
|
| 683 | + $str->string = $string . implode('', $chars); |
|
| 684 | 684 | |
| 685 | 685 | return $str; |
| 686 | 686 | } |
@@ -141,7 +141,7 @@ |
||
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - return [$singular.'s']; |
|
| 144 | + return [$singular . 's']; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | private function isInflectedWord(string $word): bool |
@@ -487,13 +487,13 @@ discard block |
||
| 487 | 487 | $singulars = []; |
| 488 | 488 | |
| 489 | 489 | foreach ($newSuffix as $newSuffixEntry) { |
| 490 | - $singulars[] = $newBase.($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); |
|
| 490 | + $singulars[] = $newBase . ($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); |
|
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | return $singulars; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - return [$newBase.($firstUpper ? ucfirst($newSuffix) : $newSuffix)]; |
|
| 496 | + return [$newBase . ($firstUpper ? ucfirst($newSuffix) : $newSuffix)]; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | // Suffix is longer than word |
@@ -564,13 +564,13 @@ discard block |
||
| 564 | 564 | $plurals = []; |
| 565 | 565 | |
| 566 | 566 | foreach ($newSuffix as $newSuffixEntry) { |
| 567 | - $plurals[] = $newBase.($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); |
|
| 567 | + $plurals[] = $newBase . ($firstUpper ? ucfirst($newSuffixEntry) : $newSuffixEntry); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | return $plurals; |
| 571 | 571 | } |
| 572 | 572 | |
| 573 | - return [$newBase.($firstUpper ? ucfirst($newSuffix) : $newSuffix)]; |
|
| 573 | + return [$newBase . ($firstUpper ? ucfirst($newSuffix) : $newSuffix)]; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | // Suffix is longer than word |
@@ -581,6 +581,6 @@ discard block |
||
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | // Assume that plural is singular with a trailing `s` |
| 584 | - return [$singular.'s']; |
|
| 584 | + return [$singular . 's']; |
|
| 585 | 585 | } |
| 586 | 586 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | return $chunks; |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - public function endsWith(string|iterable|AbstractString $suffix): bool |
|
| 135 | + public function endsWith(string | iterable | AbstractString $suffix): bool |
|
| 136 | 136 | { |
| 137 | 137 | if ($suffix instanceof AbstractString) { |
| 138 | 138 | $suffix = $suffix->string; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | return '' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - public function equalsTo(string|iterable|AbstractString $string): bool |
|
| 146 | + public function equalsTo(string | iterable | AbstractString $string): bool |
|
| 147 | 147 | { |
| 148 | 148 | if ($string instanceof AbstractString) { |
| 149 | 149 | $string = $string->string; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | return $str; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function indexOf(string|iterable|AbstractString $needle, int $offset = 0): ?int |
|
| 169 | + public function indexOf(string | iterable | AbstractString $needle, int $offset = 0): ?int |
|
| 170 | 170 | { |
| 171 | 171 | if ($needle instanceof AbstractString) { |
| 172 | 172 | $needle = $needle->string; |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | return false === $i ? null : $i; |
| 184 | 184 | } |
| 185 | 185 | |
| 186 | - public function indexOfLast(string|iterable|AbstractString $needle, int $offset = 0): ?int |
|
| 186 | + public function indexOfLast(string | iterable | AbstractString $needle, int $offset = 0): ?int |
|
| 187 | 187 | { |
| 188 | 188 | if ($needle instanceof AbstractString) { |
| 189 | 189 | $needle = $needle->string; |
@@ -209,8 +209,8 @@ discard block |
||
| 209 | 209 | { |
| 210 | 210 | $str = clone $this; |
| 211 | 211 | |
| 212 | - $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue.array_pop($strings) : ''; |
|
| 213 | - $str->string = implode($this->string, $strings).$tail; |
|
| 212 | + $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . array_pop($strings) : ''; |
|
| 213 | + $str->string = implode($this->string, $strings) . $tail; |
|
| 214 | 214 | |
| 215 | 215 | return $str; |
| 216 | 216 | } |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | try { |
| 242 | 242 | if (false === $match($regexp, $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { |
| 243 | - throw new RuntimeException('Matching failed with error: '.preg_last_error_msg()); |
|
| 243 | + throw new RuntimeException('Matching failed with error: ' . preg_last_error_msg()); |
|
| 244 | 244 | } |
| 245 | 245 | } finally { |
| 246 | 246 | restore_error_handler(); |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | public function prepend(string ...$prefix): static |
| 277 | 277 | { |
| 278 | 278 | $str = clone $this; |
| 279 | - $str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)).$str->string; |
|
| 279 | + $str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)) . $str->string; |
|
| 280 | 280 | |
| 281 | 281 | return $str; |
| 282 | 282 | } |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | return $str; |
| 293 | 293 | } |
| 294 | 294 | |
| 295 | - public function replaceMatches(string $fromRegexp, string|callable $to): static |
|
| 295 | + public function replaceMatches(string $fromRegexp, string | callable $to): static |
|
| 296 | 296 | { |
| 297 | 297 | if ($this->ignoreCase) { |
| 298 | 298 | $fromRegexp .= 'i'; |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | foreach (get_defined_constants(true)['pcre'] as $k => $v) { |
| 310 | 310 | if ($lastError === $v && str_ends_with($k, '_ERROR')) { |
| 311 | - throw new RuntimeException('Matching failed with '.$k.'.'); |
|
| 311 | + throw new RuntimeException('Matching failed with ' . $k . '.'); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | $str = clone $this; |
| 374 | 374 | $chunks = $this->ignoreCase |
| 375 | - ? preg_split('{'.preg_quote($delimiter).'}iD', $this->string, $limit) |
|
| 375 | + ? preg_split('{' . preg_quote($delimiter) . '}iD', $this->string, $limit) |
|
| 376 | 376 | : explode($delimiter, $this->string, $limit); |
| 377 | 377 | |
| 378 | 378 | foreach ($chunks as &$chunk) { |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | return $chunks; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | - public function startsWith(string|iterable|AbstractString $prefix): bool |
|
| 386 | + public function startsWith(string | iterable | AbstractString $prefix): bool |
|
| 387 | 387 | { |
| 388 | 388 | if ($prefix instanceof AbstractString) { |
| 389 | 389 | $prefix = $prefix->string; |
@@ -56,10 +56,10 @@ discard block |
||
| 56 | 56 | ]; |
| 57 | 57 | |
| 58 | 58 | private ?string $defaultLocale; |
| 59 | - private \Closure|array $symbolsMap = [ |
|
| 59 | + private \Closure | array $symbolsMap = [ |
|
| 60 | 60 | 'en' => ['@' => 'at', '&' => 'and'], |
| 61 | 61 | ]; |
| 62 | - private bool|string $emoji = false; |
|
| 62 | + private bool | string $emoji = false; |
|
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | 65 | * Cache of transliterators per locale. |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | */ |
| 69 | 69 | private array $transliterators = []; |
| 70 | 70 | |
| 71 | - public function __construct(?string $defaultLocale = null, array|\Closure|null $symbolsMap = null) |
|
| 71 | + public function __construct(?string $defaultLocale = null, array | \Closure | null $symbolsMap = null) |
|
| 72 | 72 | { |
| 73 | 73 | $this->defaultLocale = $defaultLocale; |
| 74 | 74 | $this->symbolsMap = $symbolsMap ?? $this->symbolsMap; |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | * false will disable emoji, |
| 93 | 93 | * and a string to use a specific locale |
| 94 | 94 | */ |
| 95 | - public function withEmoji(bool|string $emoji = true): static |
|
| 95 | + public function withEmoji(bool | string $emoji = true): static |
|
| 96 | 96 | { |
| 97 | 97 | if (false !== $emoji && !class_exists(EmojiTransliterator::class)) { |
| 98 | 98 | throw new \LogicException(sprintf('You cannot use the "%s()" method as the "symfony/intl" package is not installed. Try running "composer require symfony/intl".', __METHOD__)); |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | } |
| 142 | 142 | if ($map) { |
| 143 | 143 | foreach ($map as $char => $replace) { |
| 144 | - $unicodeString = $unicodeString->replace($char, ' '.$replace.' '); |
|
| 144 | + $unicodeString = $unicodeString->replace($char, ' ' . $replace . ' '); |
|
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | 147 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | |
| 161 | 161 | // Exact locale supported, cache and return |
| 162 | 162 | if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$locale] ?? null) { |
| 163 | - return $this->transliterators[$locale] = \Transliterator::create($id.'/BGN') ?? \Transliterator::create($id); |
|
| 163 | + return $this->transliterators[$locale] = \Transliterator::create($id . '/BGN') ?? \Transliterator::create($id); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Locale not supported and no parent, fallback to any-latin |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | // Try to use the parent locale (ie. try "de" for "de_AT") and cache both locales |
| 172 | 172 | if ($id = self::LOCALE_TO_TRANSLITERATOR_ID[$parent] ?? null) { |
| 173 | - $transliterator = \Transliterator::create($id.'/BGN') ?? \Transliterator::create($id); |
|
| 173 | + $transliterator = \Transliterator::create($id . '/BGN') ?? \Transliterator::create($id); |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | return $this->transliterators[$locale] = $this->transliterators[$parent] = $transliterator ?? null; |
@@ -56,11 +56,11 @@ discard block |
||
| 56 | 56 | if (0x80 > $code %= 0x200000) { |
| 57 | 57 | $string .= \chr($code); |
| 58 | 58 | } elseif (0x800 > $code) { |
| 59 | - $string .= \chr(0xC0 | $code >> 6).\chr(0x80 | $code & 0x3F); |
|
| 59 | + $string .= \chr(0xC0 | $code >> 6) . \chr(0x80 | $code & 0x3F); |
|
| 60 | 60 | } elseif (0x10000 > $code) { |
| 61 | - $string .= \chr(0xE0 | $code >> 12).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
| 61 | + $string .= \chr(0xE0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F); |
|
| 62 | 62 | } else { |
| 63 | - $string .= \chr(0xF0 | $code >> 18).\chr(0x80 | $code >> 12 & 0x3F).\chr(0x80 | $code >> 6 & 0x3F).\chr(0x80 | $code & 0x3F); |
|
| 63 | + $string .= \chr(0xF0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3F) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | } elseif (!\function_exists('iconv')) { |
| 136 | 136 | $s = preg_replace('/[^\x00-\x7F]/u', '?', $s); |
| 137 | 137 | } else { |
| 138 | - $s = @preg_replace_callback('/[^\x00-\x7F]/u', static function ($c) { |
|
| 138 | + $s = @preg_replace_callback('/[^\x00-\x7F]/u', static function($c) { |
|
| 139 | 139 | $c = (string) iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]); |
| 140 | 140 | |
| 141 | 141 | if ('' === $c && '' === iconv('UTF-8', 'ASCII//TRANSLIT', '²')) { |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | public function camel(): static |
| 156 | 156 | { |
| 157 | 157 | $str = clone $this; |
| 158 | - $str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function ($m) { |
|
| 158 | + $str->string = str_replace(' ', '', preg_replace_callback('/\b.(?!\p{Lu})/u', static function($m) { |
|
| 159 | 159 | static $i = 0; |
| 160 | 160 | |
| 161 | 161 | return 1 === ++$i ? ('İ' === $m[0] ? 'i̇' : mb_strtolower($m[0], 'UTF-8')) : mb_convert_case($m[0], \MB_CASE_TITLE, 'UTF-8'); |
@@ -202,8 +202,8 @@ discard block |
||
| 202 | 202 | { |
| 203 | 203 | $str = clone $this; |
| 204 | 204 | |
| 205 | - $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue.array_pop($strings) : ''; |
|
| 206 | - $str->string = implode($this->string, $strings).$tail; |
|
| 205 | + $tail = null !== $lastGlue && 1 < \count($strings) ? $lastGlue . array_pop($strings) : ''; |
|
| 206 | + $str->string = implode($this->string, $strings) . $tail; |
|
| 207 | 207 | |
| 208 | 208 | if (!preg_match('//u', $str->string)) { |
| 209 | 209 | throw new InvalidArgumentException('Invalid UTF-8 string.'); |
@@ -231,8 +231,8 @@ discard block |
||
| 231 | 231 | set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); |
| 232 | 232 | |
| 233 | 233 | try { |
| 234 | - if (false === $match($regexp.'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { |
|
| 235 | - throw new RuntimeException('Matching failed with error: '.preg_last_error_msg()); |
|
| 234 | + if (false === $match($regexp . 'u', $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) { |
|
| 235 | + throw new RuntimeException('Matching failed with error: ' . preg_last_error_msg()); |
|
| 236 | 236 | } |
| 237 | 237 | } finally { |
| 238 | 238 | restore_error_handler(); |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | return $this->pad($length, $pad, \STR_PAD_LEFT); |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - public function replaceMatches(string $fromRegexp, string|callable $to): static |
|
| 292 | + public function replaceMatches(string $fromRegexp, string | callable $to): static |
|
| 293 | 293 | { |
| 294 | 294 | if ($this->ignoreCase) { |
| 295 | 295 | $fromRegexp .= 'i'; |
@@ -297,7 +297,7 @@ discard block |
||
| 297 | 297 | |
| 298 | 298 | if (\is_array($to) || $to instanceof \Closure) { |
| 299 | 299 | $replace = 'preg_replace_callback'; |
| 300 | - $to = static function (array $m) use ($to): string { |
|
| 300 | + $to = static function(array $m) use ($to): string { |
|
| 301 | 301 | $to = $to($m); |
| 302 | 302 | |
| 303 | 303 | if ('' !== $to && (!\is_string($to) || !preg_match('//u', $to))) { |
@@ -315,12 +315,12 @@ discard block |
||
| 315 | 315 | set_error_handler(static fn ($t, $m) => throw new InvalidArgumentException($m)); |
| 316 | 316 | |
| 317 | 317 | try { |
| 318 | - if (null === $string = $replace($fromRegexp.'u', $to, $this->string)) { |
|
| 318 | + if (null === $string = $replace($fromRegexp . 'u', $to, $this->string)) { |
|
| 319 | 319 | $lastError = preg_last_error(); |
| 320 | 320 | |
| 321 | 321 | foreach (get_defined_constants(true)['pcre'] as $k => $v) { |
| 322 | 322 | if ($lastError === $v && str_ends_with($k, '_ERROR')) { |
| 323 | - throw new RuntimeException('Matching failed with '.$k.'.'); |
|
| 323 | + throw new RuntimeException('Matching failed with ' . $k . '.'); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | |
@@ -496,22 +496,22 @@ discard block |
||
| 496 | 496 | |
| 497 | 497 | switch ($type) { |
| 498 | 498 | case \STR_PAD_RIGHT: |
| 499 | - return $this->append(str_repeat($pad->string, intdiv($freeLen, $padLen)).($len ? $pad->slice(0, $len) : '')); |
|
| 499 | + return $this->append(str_repeat($pad->string, intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); |
|
| 500 | 500 | |
| 501 | 501 | case \STR_PAD_LEFT: |
| 502 | - return $this->prepend(str_repeat($pad->string, intdiv($freeLen, $padLen)).($len ? $pad->slice(0, $len) : '')); |
|
| 502 | + return $this->prepend(str_repeat($pad->string, intdiv($freeLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); |
|
| 503 | 503 | |
| 504 | 504 | case \STR_PAD_BOTH: |
| 505 | 505 | $freeLen /= 2; |
| 506 | 506 | |
| 507 | 507 | $rightLen = ceil($freeLen); |
| 508 | 508 | $len = $rightLen % $padLen; |
| 509 | - $str = $this->append(str_repeat($pad->string, intdiv($rightLen, $padLen)).($len ? $pad->slice(0, $len) : '')); |
|
| 509 | + $str = $this->append(str_repeat($pad->string, intdiv($rightLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); |
|
| 510 | 510 | |
| 511 | 511 | $leftLen = floor($freeLen); |
| 512 | 512 | $len = $leftLen % $padLen; |
| 513 | 513 | |
| 514 | - return $str->prepend(str_repeat($pad->string, intdiv($leftLen, $padLen)).($len ? $pad->slice(0, $len) : '')); |
|
| 514 | + return $str->prepend(str_repeat($pad->string, intdiv($leftLen, $padLen)) . ($len ? $pad->slice(0, $len) : '')); |
|
| 515 | 515 | |
| 516 | 516 | default: |
| 517 | 517 | throw new InvalidArgumentException('Invalid padding type.'); |
@@ -546,7 +546,7 @@ discard block |
||
| 546 | 546 | return -1; |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | - self::$tableZero ??= require __DIR__.'/Resources/data/wcswidth_table_zero.php'; |
|
| 549 | + self::$tableZero ??= require __DIR__ . '/Resources/data/wcswidth_table_zero.php'; |
|
| 550 | 550 | |
| 551 | 551 | if ($codePoint >= self::$tableZero[0][0] && $codePoint <= self::$tableZero[$ubound = \count(self::$tableZero) - 1][1]) { |
| 552 | 552 | $lbound = 0; |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | } |
| 564 | 564 | } |
| 565 | 565 | |
| 566 | - self::$tableWide ??= require __DIR__.'/Resources/data/wcswidth_table_wide.php'; |
|
| 566 | + self::$tableWide ??= require __DIR__ . '/Resources/data/wcswidth_table_wide.php'; |
|
| 567 | 567 | |
| 568 | 568 | if ($codePoint >= self::$tableWide[0][0] && $codePoint <= self::$tableWide[$ubound = \count(self::$tableWide) - 1][1]) { |
| 569 | 569 | $lbound = 0; |
@@ -60,18 +60,18 @@ |
||
| 60 | 60 | } |
| 61 | 61 | foreach ($suffixes as $suffix) { |
| 62 | 62 | foreach ($dirs as $dir) { |
| 63 | - if (@is_file($file = $dir.\DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) { |
|
| 63 | + if (@is_file($file = $dir . \DIRECTORY_SEPARATOR . $name . $suffix) && ('\\' === \DIRECTORY_SEPARATOR || @is_executable($file))) { |
|
| 64 | 64 | return $file; |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | - if (!@is_dir($dir) && basename($dir) === $name.$suffix && @is_executable($dir)) { |
|
| 67 | + if (!@is_dir($dir) && basename($dir) === $name . $suffix && @is_executable($dir)) { |
|
| 68 | 68 | return $dir; |
| 69 | 69 | } |
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --'; |
| 74 | - if (\function_exists('exec') && ($executablePath = strtok(@exec($command.' '.escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) { |
|
| 74 | + if (\function_exists('exec') && ($executablePath = strtok(@exec($command . ' ' . escapeshellarg($name)), \PHP_EOL)) && @is_executable($executablePath)) { |
|
| 75 | 75 | return $executablePath; |
| 76 | 76 | } |
| 77 | 77 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | if ($php = getenv('PHP_BINARY')) { |
| 37 | 37 | if (!is_executable($php)) { |
| 38 | 38 | $command = '\\' === \DIRECTORY_SEPARATOR ? 'where' : 'command -v --'; |
| 39 | - if (\function_exists('exec') && $php = strtok(exec($command.' '.escapeshellarg($php)), \PHP_EOL)) { |
|
| 39 | + if (\function_exists('exec') && $php = strtok(exec($command . ' ' . escapeshellarg($php)), \PHP_EOL)) { |
|
| 40 | 40 | if (!is_executable($php)) { |
| 41 | 41 | return false; |
| 42 | 42 | } |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $args = $this->findArguments(); |
| 56 | - $args = $includeArgs && $args ? ' '.implode(' ', $args) : ''; |
|
| 56 | + $args = $includeArgs && $args ? ' ' . implode(' ', $args) : ''; |
|
| 57 | 57 | |
| 58 | 58 | // PHP_BINARY return the current sapi executable |
| 59 | 59 | if (\PHP_BINARY && \in_array(\PHP_SAPI, ['cli', 'cli-server', 'phpdbg'], true)) { |
| 60 | - return \PHP_BINARY.$args; |
|
| 60 | + return \PHP_BINARY . $args; |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if ($php = getenv('PHP_PATH')) { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - if (@is_executable($php = \PHP_BINDIR.('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) { |
|
| 77 | + if (@is_executable($php = \PHP_BINDIR . ('\\' === \DIRECTORY_SEPARATOR ? '\\php.exe' : '/php')) && !@is_dir($php)) { |
|
| 78 | 78 | return $php; |
| 79 | 79 | } |
| 80 | 80 | |
@@ -47,9 +47,9 @@ discard block |
||
| 47 | 47 | public const TIMEOUT_PRECISION = 0.2; |
| 48 | 48 | |
| 49 | 49 | public const ITER_NON_BLOCKING = 1; // By default, iterating over outputs is a blocking call, use this flag to make it non-blocking |
| 50 | - public const ITER_KEEP_OUTPUT = 2; // By default, outputs are cleared while iterating, use this flag to keep them in memory |
|
| 51 | - public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating |
|
| 52 | - public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating |
|
| 50 | + public const ITER_KEEP_OUTPUT = 2; // By default, outputs are cleared while iterating, use this flag to keep them in memory |
|
| 51 | + public const ITER_SKIP_OUT = 4; // Use this flag to skip STDOUT while iterating |
|
| 52 | + public const ITER_SKIP_ERR = 8; // Use this flag to skip STDERR while iterating |
|
| 53 | 53 | |
| 54 | 54 | private $callback; |
| 55 | 55 | private $hasCallback = false; |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | public function __sleep() |
| 205 | 205 | { |
| 206 | - throw new \BadMethodCallException('Cannot serialize '.__CLASS__); |
|
| 206 | + throw new \BadMethodCallException('Cannot serialize ' . __CLASS__); |
|
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | public function __wakeup() |
| 210 | 210 | { |
| 211 | - throw new \BadMethodCallException('Cannot unserialize '.__CLASS__); |
|
| 211 | + throw new \BadMethodCallException('Cannot unserialize ' . __CLASS__); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | public function __destruct() |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | if ('\\' !== \DIRECTORY_SEPARATOR) { |
| 320 | 320 | // exec is mandatory to deal with sending a signal to the process |
| 321 | - $commandline = 'exec '.$commandline; |
|
| 321 | + $commandline = 'exec ' . $commandline; |
|
| 322 | 322 | } |
| 323 | 323 | } else { |
| 324 | 324 | $commandline = $this->replacePlaceholders($commandline, $env); |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | $descriptors[3] = ['pipe', 'w']; |
| 332 | 332 | |
| 333 | 333 | // See https://unix.stackexchange.com/questions/71205/background-process-pipe-input |
| 334 | - $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;'; |
|
| 334 | + $commandline = '{ (' . $commandline . ') <&3 3<&- 3>/dev/null & } 3<&0;'; |
|
| 335 | 335 | $commandline .= 'pid=$!; echo $pid >&3; wait $pid 2>/dev/null; code=$?; echo $code >&3; exit $code'; |
| 336 | 336 | |
| 337 | 337 | // Workaround for the bug, when PTS functionality is enabled. |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | $envPairs = []; |
| 343 | 343 | foreach ($env as $k => $v) { |
| 344 | 344 | if (false !== $v && false === \in_array($k, ['argc', 'argv', 'ARGC', 'ARGV'], true)) { |
| 345 | - $envPairs[] = $k.'='.$v; |
|
| 345 | + $envPairs[] = $k . '=' . $v; |
|
| 346 | 346 | } |
| 347 | 347 | } |
| 348 | 348 | |
@@ -1314,14 +1314,14 @@ discard block |
||
| 1314 | 1314 | protected function buildCallback(?callable $callback = null) |
| 1315 | 1315 | { |
| 1316 | 1316 | if ($this->outputDisabled) { |
| 1317 | - return function ($type, $data) use ($callback): bool { |
|
| 1317 | + return function($type, $data) use ($callback): bool { |
|
| 1318 | 1318 | return null !== $callback && $callback($type, $data); |
| 1319 | 1319 | }; |
| 1320 | 1320 | } |
| 1321 | 1321 | |
| 1322 | 1322 | $out = self::OUT; |
| 1323 | 1323 | |
| 1324 | - return function ($type, $data) use ($callback, $out): bool { |
|
| 1324 | + return function($type, $data) use ($callback, $out): bool { |
|
| 1325 | 1325 | if ($out == $type) { |
| 1326 | 1326 | $this->addOutput($data); |
| 1327 | 1327 | } else { |
@@ -1491,8 +1491,8 @@ discard block |
||
| 1491 | 1491 | $this->exitcode = null; |
| 1492 | 1492 | $this->fallbackStatus = []; |
| 1493 | 1493 | $this->processInformation = null; |
| 1494 | - $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+'); |
|
| 1495 | - $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'w+'); |
|
| 1494 | + $this->stdout = fopen('php://temp/maxmemory:' . (1024 * 1024), 'w+'); |
|
| 1495 | + $this->stderr = fopen('php://temp/maxmemory:' . (1024 * 1024), 'w+'); |
|
| 1496 | 1496 | $this->process = null; |
| 1497 | 1497 | $this->latestSignal = null; |
| 1498 | 1498 | $this->status = self::STATUS_READY; |
@@ -1567,7 +1567,7 @@ discard block |
||
| 1567 | 1567 | [^"%!^]*+ |
| 1568 | 1568 | )++ |
| 1569 | 1569 | ) | [^"]*+ )"/x', |
| 1570 | - function ($m) use (&$env, &$varCache, &$varCount, $uid) { |
|
| 1570 | + function($m) use (&$env, &$varCache, &$varCount, $uid) { |
|
| 1571 | 1571 | if (!isset($m[1])) { |
| 1572 | 1572 | return $m[0]; |
| 1573 | 1573 | } |
@@ -1578,23 +1578,23 @@ discard block |
||
| 1578 | 1578 | $value = str_replace("\0", '?', $value); |
| 1579 | 1579 | } |
| 1580 | 1580 | if (false === strpbrk($value, "\"%!\n")) { |
| 1581 | - return '"'.$value.'"'; |
|
| 1581 | + return '"' . $value . '"'; |
|
| 1582 | 1582 | } |
| 1583 | 1583 | |
| 1584 | 1584 | $value = str_replace(['!LF!', '"^!"', '"^%"', '"^^"', '""'], ["\n", '!', '%', '^', '"'], $value); |
| 1585 | - $value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"'; |
|
| 1586 | - $var = $uid.++$varCount; |
|
| 1585 | + $value = '"' . preg_replace('/(\\\\*)"/', '$1$1\\"', $value) . '"'; |
|
| 1586 | + $var = $uid . ++$varCount; |
|
| 1587 | 1587 | |
| 1588 | 1588 | $env[$var] = $value; |
| 1589 | 1589 | |
| 1590 | - return $varCache[$m[0]] = '!'.$var.'!'; |
|
| 1590 | + return $varCache[$m[0]] = '!' . $var . '!'; |
|
| 1591 | 1591 | }, |
| 1592 | 1592 | $cmd |
| 1593 | 1593 | ); |
| 1594 | 1594 | |
| 1595 | - $cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')'; |
|
| 1595 | + $cmd = 'cmd /V:ON /E:ON /D /C (' . str_replace("\n", ' ', $cmd) . ')'; |
|
| 1596 | 1596 | foreach ($this->processPipes->getFiles() as $offset => $filename) { |
| 1597 | - $cmd .= ' '.$offset.'>"'.$filename.'"'; |
|
| 1597 | + $cmd .= ' ' . $offset . '>"' . $filename . '"'; |
|
| 1598 | 1598 | } |
| 1599 | 1599 | |
| 1600 | 1600 | return $cmd; |
@@ -1633,7 +1633,7 @@ discard block |
||
| 1633 | 1633 | return '""'; |
| 1634 | 1634 | } |
| 1635 | 1635 | if ('\\' !== \DIRECTORY_SEPARATOR) { |
| 1636 | - return "'".str_replace("'", "'\\''", $argument)."'"; |
|
| 1636 | + return "'" . str_replace("'", "'\\''", $argument) . "'"; |
|
| 1637 | 1637 | } |
| 1638 | 1638 | if (str_contains($argument, "\0")) { |
| 1639 | 1639 | $argument = str_replace("\0", '?', $argument); |
@@ -1643,14 +1643,14 @@ discard block |
||
| 1643 | 1643 | } |
| 1644 | 1644 | $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument); |
| 1645 | 1645 | |
| 1646 | - return '"'.str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument).'"'; |
|
| 1646 | + return '"' . str_replace(['"', '^', '%', '!', "\n"], ['""', '"^^"', '"^%"', '"^!"', '!LF!'], $argument) . '"'; |
|
| 1647 | 1647 | } |
| 1648 | 1648 | |
| 1649 | 1649 | private function replacePlaceholders(string $commandline, array $env) |
| 1650 | 1650 | { |
| 1651 | - return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function ($matches) use ($commandline, $env) { |
|
| 1651 | + return preg_replace_callback('/"\$\{:([_a-zA-Z]++[_a-zA-Z0-9]*+)\}"/', function($matches) use ($commandline, $env) { |
|
| 1652 | 1652 | if (!isset($env[$matches[1]]) || false === $env[$matches[1]]) { |
| 1653 | - throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": ', $matches[1]).$commandline); |
|
| 1653 | + throw new InvalidArgumentException(sprintf('Command line is missing a value for parameter "%s": ', $matches[1]) . $commandline); |
|
| 1654 | 1654 | } |
| 1655 | 1655 | |
| 1656 | 1656 | return $this->escapeArgument($env[$matches[1]]); |