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

DeviceModel::setDeviceName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * @author Sergey Nehaenko <[email protected]>
4
 * @license GPL
5
 * @copyright Sergey Nehaenko &copy 2016
6
 * @version 1.0
7
 * @project browser-detector
8
 */
9
10
namespace EndorphinStudio\Detector;
11
12
13
class DeviceModel
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getId()
19
    {
20
        return $this->id;
21
    }
22
23
    /**
24
     * @param string $id
25
     */
26
    public function setId($id)
27
    {
28
        $this->id = $id;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getDeviceName()
35
    {
36
        return $this->deviceName;
37
    }
38
39
    /**
40
     * @param string $deviceName
41
     */
42
    public function setDeviceName($deviceName)
43
    {
44
        $this->deviceName = $deviceName;
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function getPattern()
51
    {
52
        return $this->pattern;
53
    }
54
55
    /**
56
     * @param string $pattern
57
     */
58
    public function setPattern($pattern)
59
    {
60
        $this->pattern = $pattern;
61
    }
62
63
    private $id;
64
65
    private $deviceName;
66
67
    private $pattern;
68
69
    public function __construct(\SimpleXMLElement $xmlData)
70
    {
71
        if($xmlData !== null)
72
        {
73
            foreach ($xmlData->children() as $child)
74
            {
75
                $name = $child->getName();
76
                $val = $child->__toString();
77
                $this->$name = $val;
78
            }
79
        }
80
    }
81
82
    /**
83
     * @return array Array of EndorphinStudio\Detector\DeviceModel objects
84
     */
85
    public static function loadFromFile()
86
    {
87
        $path = str_replace('src','data',__DIR__).'/deviceModels.xml';
88
        $models = array();
89
        $xmlObj = simplexml_load_file($path);
90
        foreach($xmlObj->children() as $rule)
91
        {
92
            $models[] = new self($rule);
93
        }
94
95
        return $models;
96
    }
97
}