HtmlNormalizer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
c 0
b 0
f 0
dl 0
loc 28
ccs 0
cts 8
cp 0
rs 10

3 Methods

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