Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
80.00% covered (warning)
80.00%
4 / 5
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
HtmlArmor
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
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
 getHtml
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 * @license GPL-2.0-or-later
6 * @author Kunal Mehta <legoktm@debian.org>
7 */
8
9namespace Wikimedia\HtmlArmor;
10
11/**
12 * Marks HTML that shouldn't be escaped
13 *
14 * @newable
15 *
16 * @since 1.28
17 */
18class HtmlArmor {
19
20    /**
21     * @var string|null
22     */
23    private $value;
24
25    /**
26     * @stable to call
27     *
28     * @param string|null $value
29     * @param-taint $value exec_html
30     */
31    public function __construct( $value ) {
32        $this->value = $value;
33    }
34
35    /**
36     * Provide a string or HtmlArmor object
37     * and get safe HTML back
38     *
39     * @param string|HtmlArmor $input
40     * @return string|null safe for usage in HTML, or null
41     *         if the HtmlArmor instance was wrapping null.
42     */
43    public static function getHtml( $input ) {
44        if ( $input instanceof HtmlArmor ) {
45            return $input->value;
46        } else {
47            return htmlspecialchars( $input, ENT_QUOTES );
48        }
49    }
50}
51
52/** @deprecated class alias since 1.44 */
53class_alias( HtmlArmor::class, 'HtmlArmor' );