Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
2 / 2
CRAP
n/a
0 / 0
u
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
w
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5use Celema\Boiler\Exception\LogicException;
6use Celema\Boiler\Proxy\ArrayProxy;
7use Celema\Boiler\Proxy\IteratorProxy;
8use Celema\Boiler\Proxy\ObjectProxy;
9use Celema\Boiler\Proxy\Proxy;
10use Celema\Boiler\Proxy\StringProxy;
11use Celema\Boiler\TemplateFunctions;
12
13use 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 */
27function 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 */
45function 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}