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

HtmlNormalizer   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 56
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldEncode() 0 4 1
A setEncode() 0 6 1
A setFlags() 0 6 1
A getFlags() 0 4 1
A getNormalizedValue() 0 10 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