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

Robot::__construct()   C

Complexity

Conditions 7
Paths 7

Size

Total Lines 29
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 7
eloc 18
c 3
b 0
f 0
nc 7
nop 1
dl 0
loc 29
rs 6.7272
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 Robot extends Data
14
{
15
    /**
16
     * @return string
17
     */
18
    public function getHomepage()
19
    {
20
        return $this->Homepage;
21
    }
22
23
    /**
24
     * @return boolean
25
     */
26
    public function isSearchEngine()
27
    {
28
        return $this->SearchEngine;
29
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getOwner()
35
    {
36
        return $this->Owner;
37
    }
38
39
    /**
40
     * @param string $Homepage
41
     */
42
    public function setHomepage($Homepage)
43
    {
44
        $this->Homepage = $Homepage;
45
    }
46
47
    /**
48
     * @param string $Owner
49
     */
50
    public function setOwner($Owner)
51
    {
52
        $this->Owner = $Owner;
53
    }
54
55
    /**
56
     * @param boolean $isSearchEngine
57
     */
58
    public function setSearchEngine($isSearchEngine)
59
    {
60
        $this->SearchEngine = $isSearchEngine;
61
    }
62
    /** @var string Crawler homepage */
63
    private $Homepage = D_NA;
64
65
    /** @var boolean Search Engine */
66
    private $SearchEngine = false;
67
68
    /** @var string Crawler Owner */
69
    private $Owner = D_NA;
70
71
    public function __construct(\SimpleXMLElement $xmlData)
72
    {
73
        parent::__construct($xmlData);
74
75
        if($xmlData !== null)
76
        {
77
            foreach ($xmlData->children() as $child)
78
            {
79
                switch ($child->getName())
80
                {
81
                    case 'url':
82
                        $this->Homepage = $child->__toString();
83
                        break;
84
                    case 'owner':
85
                        $this->Owner = $child->__toString();
86
                        break;
87
                    case 'isse':
88
                        $val = $child->__toString();
89
                        if($val == 'true')
90
                        {
91
                            $this->setSearchEngine(true);
92
                        }
93
                        else
94
                            $this->setSearchEngine(false);
95
                        break;
96
                }
97
            }
98
        }
99
    }
100
101
    public static function initEmpty()
102
    {
103
        return new self(new \SimpleXMLElement('<null>null</null>'));
104
    }
105
}
106