Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
Text
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Epic64\Elem\Elements;
6
7/**
8 * Represents a text node that will be safely escaped when rendered.
9 *
10 * This is useful when you want to explicitly create a text node as a sibling
11 * to other elements, rather than using the `text` parameter of an element.
12 *
13 * @example
14 * ```php
15 * div()(
16 *     text('Hello, '),
17 *     span(class: 'name', text: $username),
18 *     text('!')
19 * )
20 * ```
21 */
22class Text
23{
24    public function __construct(
25        public readonly string $content
26    ) {}
27
28    public function __toString(): string
29    {
30        return htmlspecialchars($this->content, ENT_QUOTES | ENT_HTML5, 'UTF-8');
31    }
32}