Completed
Pull Request — master (#8)
by Serhii
01:59
created

Data::initEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @author Sergey Nehaenko <[email protected]>
4
 * @license GPL
5
 * @copyright Sergey Nehaenko &copy 2016
6
 * @version 3.0.0
7
 * @project browser-detector
8
 */
9
10
namespace EndorphinStudio\Detector;
11
12
13
class Data
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getName()
19
    {
20
        return $this->Name;
21
    }
22
23
    /**
24
     * @return string
25
     */
26
    public function getType()
27
    {
28
        return $this->Type;
29
    }
30
31
    /**
32
     * @param string $Name
33
     */
34
    public function setName($Name)
35
    {
36
        $this->Name = $Name;
37
    }
38
39
    /**
40
     * @param string $Type
41
     */
42
    public function setType($Type)
43
    {
44
        $this->Type = $Type;
45
    }
46
    /**
47
     * @var string Name
48
     */
49
    protected $Name = D_NA;
50
    /** @var string Type */
51
    protected $Type = D_NA;
52
53
    /**
54
     * Data constructor.
55
     * @param \SimpleXMLElement $xmlData Xml data from file
56
     */
57
    public function __construct(\SimpleXMLElement $xmlData)
58
    {
59
        if($xmlData !== null)
60
        {
61
            foreach ($xmlData->children() as $child) {
62
                switch ($child->getName()) {
63
                    case 'name':
64
                        $this->Name = $child->__toString();
65
                        break;
66
                    case 'type':
67
                        $this->Type = $child->__toString();
68
                        break;
69
                }
70
            }
71
        }
72
    }
73
74
    public static function initEmpty()
75
    {
76
        return new self(new \SimpleXMLElement('<null>null</null>'));
77
    }
78
}
79