Localization_Scanner_StringInfo   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 43
dl 0
loc 147
rs 10
c 1
b 0
f 0
wmc 18

16 Methods

Rating   Name   Duplication   Size   Complexity  
A getSourceFile() 0 3 1
A __construct() 0 6 1
A getProperties() 0 3 1
A getSourceType() 0 3 1
A isFile() 0 3 1
A getSourceID() 0 3 1
A isPHP() 0 3 1
A toArray() 0 7 1
A fromArray() 0 14 2
A getLanguageType() 0 3 1
A isJavascript() 0 3 1
A getHash() 0 3 1
A getLine() 0 3 1
A setProperty() 0 4 1
A getProperty() 0 7 2
A getText() 0 3 1
1
<?php
2
3
namespace AppLocalize;
4
5
use AppLocalize\Parser\Text;
6
7
class Localization_Scanner_StringInfo
8
{
9
    const SERIALIZED_SOURCE_TYPE = 'sourceType';
10
    const SERIALIZED_SOURCE_ID = 'sourceID';
11
    const SERIALIZED_TEXT = 'text';
12
    const SERIALIZED_PROPERTIES = 'properties';
13
14
    /**
15
    * @var Localization_Scanner_StringsCollection
16
    */
17
    protected $collection;
18
19
    /**
20
     * @var array<string,mixed>
21
     */
22
    protected $properties = array();
23
24
    /**
25
     * @var string
26
     */
27
    protected $sourceID;
28
29
    /**
30
     * @var string
31
     */
32
    protected $sourceType;
33
34
    /**
35
     * @var Text
36
     */
37
    protected $text;
38
    
39
    public function __construct(Localization_Scanner_StringsCollection $collection, string $sourceID, string $sourceType, Text $text)
40
    {
41
        $this->collection = $collection;
42
        $this->sourceID = $sourceID;
43
        $this->sourceType = $sourceType;
44
        $this->text = $text;
45
    }
46
    
47
    public function getHash() : string
48
    {
49
        return $this->text->getHash();
50
    }
51
    
52
    public function getSourceID() : string
53
    {
54
        return $this->sourceID;
55
    }
56
57
    /**
58
     * @param string $name
59
     * @param mixed $value
60
     * @return $this
61
     */
62
    public function setProperty(string $name, $value) : Localization_Scanner_StringInfo
63
    {
64
        $this->properties[$name] = $value;
65
        return $this;
66
    }
67
    
68
    public function isFile() : bool
69
    {
70
        return $this->sourceType == Localization_Scanner_StringsCollection::SOURCE_FILE;
71
    }
72
    
73
    public function isJavascript() : bool
74
    {
75
        return $this->getProperty('languageType') == 'Javascript';
76
    }
77
    
78
    public function isPHP() : bool
79
    {
80
        return $this->getProperty('languageType') == 'PHP';
81
    }
82
    
83
    public function getSourceFile() : string
84
    {
85
        return strval($this->getProperty('relativePath'));
86
    }
87
    
88
    public function getLanguageType() : string
89
    {
90
        return strval($this->getProperty('languageType'));
91
    }
92
    
93
    public function getProperty(string $name) : ?string
94
    {
95
        if(isset($this->properties[$name])) {
96
            return $this->properties[$name];
97
        }
98
        
99
        return null;
100
    }
101
    
102
    public function getSourceType() : string
103
    {
104
        return $this->sourceType;
105
    }
106
    
107
    public function getText() : Text
108
    {
109
        return $this->text;
110
    }
111
    
112
    public function getLine() : int
113
    {
114
        return $this->text->getLine();
115
    }
116
117
    /**
118
     * @return array<string,mixed>
119
     */
120
    public function toArray() : array
121
    {
122
        return array(
123
            self::SERIALIZED_SOURCE_TYPE => $this->getSourceType(),
124
            self::SERIALIZED_SOURCE_ID => $this->getSourceID(),
125
            self::SERIALIZED_TEXT => $this->text->toArray(),
126
            self::SERIALIZED_PROPERTIES => $this->getProperties()
127
        );
128
    }
129
    
130
    public function getProperties() : array
131
    {
132
        return $this->properties;
133
    }
134
135
    /**
136
     * @param Localization_Scanner_StringsCollection $collection
137
     * @param array<string,mixed> $array
138
     * @return Localization_Scanner_StringInfo
139
     */
140
    public static function fromArray(Localization_Scanner_StringsCollection $collection, array $array) : Localization_Scanner_StringInfo
141
    {
142
        $string = new Localization_Scanner_StringInfo(
143
            $collection, 
144
            $array[self::SERIALIZED_SOURCE_ID],
145
            $array[self::SERIALIZED_SOURCE_TYPE],
146
            Text::fromArray($array[self::SERIALIZED_TEXT])
147
        );
148
        
149
        foreach($array[self::SERIALIZED_PROPERTIES] as $name => $value) {
150
            $string->setProperty($name, $value);
151
        }
152
        
153
        return $string;
154
    }
155
}
156