| @@ -7,9 +7,9 @@ | ||
| 7 | 7 | * |
| 8 | 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | 9 | * file that was distributed with this source code. |
| 10 | 10 | */ |
| 11 | -namespace WindPressPackages\Symfony\Component\String; | |
| 11 | +namespace WindPressDeps\Symfony\Component\String; | |
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * A string whose value is computed lazily by a callback. |
| 15 | 15 | * |
| @@ -22,15 +22,15 @@ | ||
| 22 | 22 | * @param callable|array $callback A callable or a [Closure, method] lazy-callable |
| 23 | 23 | * |
| 24 | 24 | * @return static |
| 25 | 25 | */ |
| 26 | - public static function fromCallable($callback, ...$arguments) : self | |
| 26 | + public static function fromCallable($callback, ...$arguments): self | |
| 27 | 27 | { |
| 28 | 28 | if (!\is_callable($callback) && !(\is_array($callback) && isset($callback[0]) && $callback[0] instanceof \Closure && 2 >= \count($callback))) { |
| 29 | - throw new \TypeError(\sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, \get_debug_type($callback))); | |
| 29 | + throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, get_debug_type($callback))); | |
| 30 | 30 | } |
| 31 | 31 | $lazyString = new static(); |
| 32 | - $lazyString->value = static function () use(&$callback, &$arguments, &$value) : string { | |
| 32 | + $lazyString->value = static function () use (&$callback, &$arguments, &$value): string { | |
| 33 | 33 | if (null !== $arguments) { |
| 34 | 34 | if (!\is_callable($callback)) { |
| 35 | 35 | $callback[0] = $callback[0](); |
| 36 | 36 | $callback[1] = $callback[1] ?? '__invoke'; |
| @@ -47,12 +47,12 @@ | ||
| 47 | 47 | * @param string|int|float|bool|\Stringable $value |
| 48 | 48 | * |
| 49 | 49 | * @return static |
| 50 | 50 | */ |
| 51 | - public static function fromStringable($value) : self | |
| 51 | + public static function fromStringable($value): self | |
| 52 | 52 | { |
| 53 | 53 | if (!self::isStringable($value)) { |
| 54 | - throw new \TypeError(\sprintf('Argument 1 passed to "%s()" must be a scalar or a stringable object, "%s" given.', __METHOD__, \get_debug_type($value))); | |
| 54 | + throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a scalar or a stringable object, "%s" given.', __METHOD__, get_debug_type($value))); | |
| 55 | 55 | } |
| 56 | 56 | if (\is_object($value)) { |
| 57 | 57 | return static::fromCallable([$value, '__toString']); |
| 58 | 58 | } |
| @@ -62,11 +62,11 @@ | ||
| 62 | 62 | } |
| 63 | 63 | /** |
| 64 | 64 | * Tells whether the provided value can be cast to string. |
| 65 | 65 | */ |
| 66 | - public static final function isStringable($value) : bool | |
| 66 | + final public static function isStringable($value): bool | |
| 67 | 67 | { |
| 68 | - return \is_string($value) || $value instanceof self || (\is_object($value) ? \method_exists($value, '__toString') : \is_scalar($value)); | |
| 68 | + return \is_string($value) || $value instanceof self || (\is_object($value) ? method_exists($value, '__toString') : \is_scalar($value)); | |
| 69 | 69 | } |
| 70 | 70 | /** |
| 71 | 71 | * Casts scalars and stringable objects to strings. |
| 72 | 72 | * |
| @@ -73,9 +73,9 @@ | ||
| 73 | 73 | * @param object|string|int|float|bool $value |
| 74 | 74 | * |
| 75 | 75 | * @throws \TypeError When the provided value is not stringable |
| 76 | 76 | */ |
| 77 | - public static final function resolve($value) : string | |
| 77 | + final public static function resolve($value): string | |
| 78 | 78 | { |
| 79 | 79 | return $value; |
| 80 | 80 | } |
| 81 | 81 | /** |
| @@ -89,27 +89,27 @@ | ||
| 89 | 89 | try { |
| 90 | 90 | return $this->value = ($this->value)(); |
| 91 | 91 | } catch (\Throwable $e) { |
| 92 | 92 | if (\TypeError::class === \get_class($e) && __FILE__ === $e->getFile()) { |
| 93 | - $type = \explode(', ', $e->getMessage()); | |
| 94 | - $type = \substr(\array_pop($type), 0, -\strlen(' returned')); | |
| 93 | + $type = explode(', ', $e->getMessage()); | |
| 94 | + $type = substr(array_pop($type), 0, -\strlen(' returned')); | |
| 95 | 95 | $r = new \ReflectionFunction($this->value); |
| 96 | 96 | $callback = $r->getStaticVariables()['callback']; |
| 97 | - $e = new \TypeError(\sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type)); | |
| 97 | + $e = new \TypeError(sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type)); | |
| 98 | 98 | } |
| 99 | 99 | if (\PHP_VERSION_ID < 70400) { |
| 100 | 100 | // leverage the ErrorHandler component with graceful fallback when it's not available |
| 101 | - return \trigger_error($e, \E_USER_ERROR); | |
| 101 | + return trigger_error($e, \E_USER_ERROR); | |
| 102 | 102 | } |
| 103 | 103 | throw $e; |
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | - public function __sleep() : array | |
| 106 | + public function __sleep(): array | |
| 107 | 107 | { |
| 108 | 108 | $this->__toString(); |
| 109 | 109 | return ['value']; |
| 110 | 110 | } |
| 111 | - public function jsonSerialize() : string | |
| 111 | + public function jsonSerialize(): string | |
| 112 | 112 | { |
| 113 | 113 | return $this->__toString(); |
| 114 | 114 | } |
| 115 | 115 | private function __construct() |
| @@ -114,25 +114,25 @@ | ||
| 114 | 114 | } |
| 115 | 115 | private function __construct() |
| 116 | 116 | { |
| 117 | 117 | } |
| 118 | - private static function getPrettyName(callable $callback) : string | |
| 118 | + private static function getPrettyName(callable $callback): string | |
| 119 | 119 | { |
| 120 | 120 | if (\is_string($callback)) { |
| 121 | 121 | return $callback; |
| 122 | 122 | } |
| 123 | 123 | if (\is_array($callback)) { |
| 124 | - $class = \is_object($callback[0]) ? \get_debug_type($callback[0]) : $callback[0]; | |
| 124 | + $class = \is_object($callback[0]) ? get_debug_type($callback[0]) : $callback[0]; | |
| 125 | 125 | $method = $callback[1]; |
| 126 | 126 | } elseif ($callback instanceof \Closure) { |
| 127 | 127 | $r = new \ReflectionFunction($callback); |
| 128 | - if (\str_contains($r->name, '{closure') || !($class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass())) { | |
| 128 | + if (str_contains($r->name, '{closure') || !$class = \PHP_VERSION_ID >= 80111 ? $r->getClosureCalledClass() : $r->getClosureScopeClass()) { | |
| 129 | 129 | return $r->name; |
| 130 | 130 | } |
| 131 | 131 | $class = $class->name; |
| 132 | 132 | $method = $r->name; |
| 133 | 133 | } else { |
| 134 | - $class = \get_debug_type($callback); | |
| 134 | + $class = get_debug_type($callback); | |
| 135 | 135 | $method = '__invoke'; |
| 136 | 136 | } |
| 137 | 137 | return $class . '::' . $method; |
| 138 | 138 | } |