Test Failed
Push — master ( c19a70...4a5f5f )
by Sebastian
05:20
created

Text::getText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AppLocalize\Parser;
6
7
class Text
8
{
9
    const SERIALIZED_TEXT = 'text';
10
    const SERIALIZED_LINE = 'line';
11
    const SERIALIZED_EXPLANATION = 'explanation';
12
    /**
13
     * @var string
14
     */
15
    private $text;
16
17
    /**
18
     * @var int
19
     */
20
    private $line;
21
22
    /**
23
     * @var string
24
     */
25
    private $explanation;
26
27
    /**
28
     * @var string
29
     */
30
    private $hash;
31
32
    public function __construct(string $text, int $line, string $explanation='')
33
    {
34
        $this->text = $text;
35
        $this->line = $line;
36
        $this->explanation = $explanation;
37
        $this->hash = md5($this->text);
38
    }
39
40
    /**
41
     * @return string
42
     */
43
    public function getExplanation() : string
44
    {
45
        return $this->explanation;
46
    }
47
48
    public function isEmpty() : bool
49
    {
50
        return $this->text === '';
51
    }
52
53
    /**
54
     * @return int
55
     */
56
    public function getLine() : int
57
    {
58
        return $this->line;
59
    }
60
61
    /**
62
     * @return string
63
     */
64
    public function getText() : string
65
    {
66
        return $this->text;
67
    }
68
69
    /**
70
     * @return string
71
     */
72
    public function getHash() : string
73
    {
74
        return $this->hash;
75
    }
76
77
    /**
78
     * @return array<string,mixed>
79
     */
80
    public function toArray() : array
81
    {
82
        return array(
83
            self::SERIALIZED_TEXT => $this->getText(),
84
            self::SERIALIZED_LINE => $this->getLine(),
85
            self::SERIALIZED_EXPLANATION => $this->getExplanation()
86
        );
87
    }
88
89
    /**
90
     * @param array<string,mixed> $array
91
     * @return Text
92
     */
93
    public static function fromArray(array $array) : Text
94
    {
95
        return new Text(
96
            $array[self::SERIALIZED_TEXT],
97
            $array[self::SERIALIZED_LINE],
98
            $array[self::SERIALIZED_EXPLANATION]
99
        );
100
    }
101
}
102