TEscapedValue   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
c 0
b 0
f 0
dl 0
loc 22
rs 10
ccs 7
cts 7
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setEscapeFlags() 0 3 1
A valueEscape() 0 5 2
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