Passed
Push — master ( 382b98...cf0bb6 )
by Gilles
08:40 queued 01:24
created

AttributeDTO::makeFromPrimitives()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPHtmlParser\DTO\Tag;
6
7
use stringEncode\Encode;
8
use stringEncode\Exception;
9
10
final class AttributeDTO
11
{
12
    /**
13
     * @var ?string
14
     */
15
    private $value;
16
17
    /**
18
     * @var bool
19
     */
20
    private $doubleQuote;
21
22 372
    private function __construct(array $values)
23
    {
24 372
        $this->value = $values['value'];
25 372
        $this->doubleQuote = $values['doubleQuote'] ?? true;
26 372
    }
27
28 372
    public static function makeFromPrimitives(?string $value, bool $doubleQuote = true): AttributeDTO
29
    {
30 372
        return new AttributeDTO([
31 372
            'value'       => $value,
32 372
            'doubleQuote' => $doubleQuote,
33
        ]);
34
    }
35
36 306
    public function getValue(): ?string
37
    {
38 306
        return $this->value;
39
    }
40
41 135
    public function isDoubleQuote(): bool
42
    {
43 135
        return $this->doubleQuote;
44
    }
45
46 3
    public function htmlspecialcharsDecode(): void
47
    {
48 3
        if (!\is_null($this->value)) {
49 3
            $this->value = \htmlspecialchars_decode($this->value);
50
        }
51 3
    }
52
53
    /**
54
     * @throws Exception
55
     */
56 201
    public function encodeValue(Encode $encode)
57
    {
58 201
        $this->value = $encode->convert($this->value);
59 201
    }
60
}
61