AttributeDTO   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 49
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 3 1
A makeFromPrimitives() 0 5 1
A encodeValue() 0 3 1
A htmlspecialcharsDecode() 0 4 2
A isDoubleQuote() 0 3 1
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 375
    private function __construct(array $values)
23
    {
24 375
        $this->value = $values['value'];
25 375
        $this->doubleQuote = $values['doubleQuote'] ?? true;
26 375
    }
27
28 375
    public static function makeFromPrimitives(?string $value, bool $doubleQuote = true): AttributeDTO
29
    {
30 375
        return new AttributeDTO([
31 375
            'value'       => $value,
32 375
            'doubleQuote' => $doubleQuote,
33
        ]);
34
    }
35
36 309
    public function getValue(): ?string
37
    {
38 309
        return $this->value;
39
    }
40
41 138
    public function isDoubleQuote(): bool
42
    {
43 138
        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 204
    public function encodeValue(Encode $encode)
57
    {
58 204
        $this->value = $encode->convert($this->value);
59 204
    }
60
}
61