Completed
Push — master ( db5ad0...ac6025 )
by Andy
06:43
created

HtmlNormalizer::setFlags()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Palmtree\Csv\Normalizer;
4
5
/**
6
 */
7
class HtmlNormalizer extends AbstractNormalizer
8
{
9
    protected $encode = true;
10
    protected $flags = ENT_QUOTES;
11
12
    /**
13
     * @return bool
14
     */
15
    public function shouldEncode()
16
    {
17
        return $this->encode;
18
    }
19
20
    /**
21
     * @param bool $encode
22
     *
23
     * @return $this
24
     */
25
    public function setEncode($encode)
26
    {
27
        $this->encode = (bool)$encode;
28
29
        return $this;
30
    }
31
32
    /**
33
     * @param int $flags
34
     *
35
     * @return $this
36
     */
37
    public function setFlags($flags)
38
    {
39
        $this->flags = (int)$flags;
40
41
        return $this;
42
    }
43
44
    /**
45
     * @return int
46
     */
47
    public function getFlags()
48
    {
49
        return $this->flags;
50
    }
51
52
    protected function getNormalizedValue($value)
53
    {
54
        if ($this->shouldEncode()) {
55
            $value = htmlentities($value, $this->getFlags());
56
        } else {
57
            $value = html_entity_decode($value, $this->getFlags());
58
        }
59
60
        return $value;
61
    }
62
}
63