Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | n/a |
0 / 0 |
|
| u | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| w | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | use Celema\Boiler\Exception\LogicException; |
| 6 | use Celema\Boiler\Proxy\ArrayProxy; |
| 7 | use Celema\Boiler\Proxy\IteratorProxy; |
| 8 | use Celema\Boiler\Proxy\ObjectProxy; |
| 9 | use Celema\Boiler\Proxy\Proxy; |
| 10 | use Celema\Boiler\Proxy\StringProxy; |
| 11 | use Celema\Boiler\TemplateFunctions; |
| 12 | |
| 13 | use function Celema\Boiler\unwrap; |
| 14 | |
| 15 | /** |
| 16 | * Returns the original of a wrapped value, for what PHP does with the value |
| 17 | * itself: conditions, comparisons, `match`, and native functions. Unwraps the |
| 18 | * items of a plain array and returns other values as they are, like |
| 19 | * `Celema\Boiler\unwrap()`, which PHP code uses. |
| 20 | * |
| 21 | * @template T |
| 22 | * |
| 23 | * @param T $value |
| 24 | * |
| 25 | * @return (T is StringProxy ? string : (T is ArrayProxy ? array<array-key, mixed> : (T is IteratorProxy ? Traversable<mixed, mixed> : (T is ObjectProxy ? object : (T is array ? array<key-of<T>, mixed> : T))))) |
| 26 | */ |
| 27 | function u(mixed $value): mixed |
| 28 | { |
| 29 | return unwrap($value); |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * Wraps a value as an escaped render passes it to a template, with the |
| 34 | * escapers, filters, and trusted classes of the render in progress, also in |
| 35 | * an unescaped render. |
| 36 | * |
| 37 | * @psalm-suppress InternalMethod the template functions are part of Boiler |
| 38 | * |
| 39 | * @template T |
| 40 | * |
| 41 | * @param T $value |
| 42 | * |
| 43 | * @return (T is string ? StringProxy : (T is array ? ArrayProxy : (T is Proxy<mixed> ? T : (T is Traversable ? IteratorProxy : (T is object ? ObjectProxy : T))))) |
| 44 | */ |
| 45 | function w(mixed $value): mixed |
| 46 | { |
| 47 | $wrapper = TemplateFunctions::wrapper() ?? throw new LogicException('w() works only while a template renders'); |
| 48 | |
| 49 | return $wrapper->wrap($value); |
| 50 | } |