TEscapedValue::setEscapeFlags()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace kalanis\kw_table\core\Table\Columns;
4
5
6
/**
7
 * Trait TEscapedValue
8
 * @package kalanis\kw_table\core\Table\Columns
9
 * Replace value selection from source, add content escape
10
 * Can be disabled due setting flag on null
11
 * Due XSS, nice for strings
12
 */
13
trait TEscapedValue
14
{
15
    protected ?int $flags = null;
16
17
    /**
18
     * @param int|null $flags example: ENT_NOQUOTES | ENT_HTML5
19
     * @link http://php.net/manual/en/function.htmlspecialchars.php
20
     */
21 1
    public function setEscapeFlags(?int $flags): void
22
    {
23 1
        $this->flags = $flags;
24 1
    }
25
26
    /**
27
     * @param float|int|string|bool|null $content
28
     * @return float|int|string|bool|null
29
     */
30 20
    protected function valueEscape($content)
31
    {
32 20
        return (is_null($this->flags))
33 20
            ? $content
34 20
            : htmlspecialchars(strval($content), $this->flags, 'UTF-8', false);
35
    }
36
}
37