HtmlNormalizer::getNormalizedValue()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Palmtree\Csv\Normalizer;
6
7
class HtmlNormalizer extends AbstractNormalizer
8
{
9
    private bool $encode = true;
10
    private int $flags = \ENT_QUOTES;
11
12
    /**
13
     * Sets whether the data should HTML encoded or returned as raw HTML. Defaults to true.
14
     */
15
    public function encode(bool $encode): self
16
    {
17
        $this->encode = $encode;
18
19
        return $this;
20
    }
21
22
    /**
23
     * Sets the flags that are passed to htmlentities and html_entity_decode. Defaults to ENT_QUOTES.
24
     */
25
    public function flags(int $flags): self
26
    {
27
        $this->flags = $flags;
28
29
        return $this;
30
    }
31
32
    protected function getNormalizedValue(string $value): string
33
    {
34
        return $this->encode ? htmlentities($value, $this->flags) : html_entity_decode($value, $this->flags);
35
    }
36
}
37