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

Device::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.5906
c 0
b 0
f 0
cc 5
eloc 12
nc 4
nop 1
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 Device extends Data
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getModelName()
19
    {
20
        return $this->ModelName;
21
    }
22
23
    /**
24
     * @param string $ModelName
25
     */
26
    public function setModelName($ModelName)
27
    {
28
        $this->ModelName = $ModelName;
29
    }
30
31
    /** @var string Model Name */
32
    public $ModelName = D_NA;
33
34
    /**
35
     * Device constructor.
36
     * @param \SimpleXMLElement $xmlData Xml data from file
37
     */
38
    public function __construct(\SimpleXMLElement $xmlData)
39
    {
40
        if($xmlData === null || $xmlData->getName() == 'null')
41
        {
42
            parent::__construct($xmlData);
43
44
            $this->setName('Desktop');
45
            $this->setType('desktop');
46
        }
47
        else
48
        {
49
            parent::__construct($xmlData);
50
51
            foreach ($xmlData->children() as $child)
52
            {
53
                switch ($child->getName()) {
54
                    case 'modelName':
55
                        $this->ModelName = $child->__toString();
56
                        break;
57
                }
58
            }
59
        }
60
    }
61
62
    public static function initEmpty()
63
    {
64
        return new self(new \SimpleXMLElement('<null>null</null>'));
65
    }
66
}
67