Completed
Branch 3.0.0 (3f0ab7)
by Serhii
03:15
created

Device::__construct()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

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