@@ -56,7 +56,7 @@ |
||
56 | 56 | */ |
57 | 57 | public function __construct(\SimpleXMLElement $xmlData) |
58 | 58 | { |
59 | - if($xmlData !== null) |
|
59 | + if ($xmlData !== null) |
|
60 | 60 | { |
61 | 61 | foreach ($xmlData->children() as $child) { |
62 | 62 | switch ($child->getName()) { |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | public function __construct(\SimpleXMLElement $xmlData) |
23 | 23 | { |
24 | 24 | parent::__construct($xmlData); |
25 | - if($xmlData !== null) |
|
25 | + if ($xmlData !== null) |
|
26 | 26 | { |
27 | 27 | foreach ($xmlData->children() as $child) { |
28 | 28 | switch ($child->getName()) { |
@@ -46,6 +46,6 @@ discard block |
||
46 | 46 | |
47 | 47 | } |
48 | 48 | |
49 | -define('UNX','unix'); |
|
50 | -define('WIN','windows'); |
|
51 | -define('MC','mac'); |
|
49 | +define('UNX', 'unix'); |
|
50 | +define('WIN', 'windows'); |
|
51 | +define('MC', 'mac'); |
@@ -21,7 +21,7 @@ |
||
21 | 21 | */ |
22 | 22 | public function __construct(\SimpleXMLElement $xmlData) |
23 | 23 | { |
24 | - if($xmlData === null || $xmlData->getName() == 'null') |
|
24 | + if ($xmlData === null || $xmlData->getName() == 'null') |
|
25 | 25 | { |
26 | 26 | parent::__construct($xmlData); |
27 | 27 |
@@ -43,8 +43,7 @@ |
||
43 | 43 | |
44 | 44 | $this->setName('Desktop'); |
45 | 45 | $this->setType('desktop'); |
46 | - } |
|
47 | - else |
|
46 | + } else |
|
48 | 47 | { |
49 | 48 | parent::__construct($xmlData); |
50 | 49 |
@@ -72,19 +72,19 @@ |
||
72 | 72 | { |
73 | 73 | parent::__construct($xmlData); |
74 | 74 | |
75 | - if($xmlData !== null) |
|
75 | + if ($xmlData !== null) |
|
76 | 76 | { |
77 | 77 | foreach ($xmlData->children() as $child) |
78 | 78 | { |
79 | 79 | $name = $child->getName(); |
80 | 80 | $val = $child->__toString(); |
81 | - if($name != 'id' && $name != 'pattern' && $name != 'SearchEngine') |
|
81 | + if ($name != 'id' && $name != 'pattern' && $name != 'SearchEngine') |
|
82 | 82 | { |
83 | 83 | $this->$name = $val; |
84 | 84 | } |
85 | - if($name == 'SearchEngine') |
|
85 | + if ($name == 'SearchEngine') |
|
86 | 86 | { |
87 | - if($val == 'true') |
|
87 | + if ($val == 'true') |
|
88 | 88 | { |
89 | 89 | $this->setSearchEngine(true); |
90 | 90 | } |
@@ -87,9 +87,9 @@ |
||
87 | 87 | if($val == 'true') |
88 | 88 | { |
89 | 89 | $this->setSearchEngine(true); |
90 | + } else { |
|
91 | + $this->setSearchEngine(false); |
|
90 | 92 | } |
91 | - else |
|
92 | - $this->setSearchEngine(false); |
|
93 | 93 | } |
94 | 94 | } |
95 | 95 | } |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | |
105 | 105 | public function __construct(\SimpleXMLElement $xmlData) |
106 | 106 | { |
107 | - if($xmlData !== null) |
|
107 | + if ($xmlData !== null) |
|
108 | 108 | { |
109 | 109 | foreach ($xmlData->children() as $child) |
110 | 110 | { |
111 | 111 | $name = $child->getName(); |
112 | 112 | $val = $child->__toString(); |
113 | - if($name != 'TargetValue') |
|
113 | + if ($name != 'TargetValue') |
|
114 | 114 | { |
115 | 115 | $this->$name = $val; |
116 | 116 | } |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | */ |
126 | 126 | public static function loadRulesFromFile() |
127 | 127 | { |
128 | - $path = str_replace('src','data',__DIR__).'/rules/'; |
|
128 | + $path = str_replace('src', 'data', __DIR__).'/rules/'; |
|
129 | 129 | $files = scandir($path); |
130 | 130 | $rules = array(); |
131 | - foreach($files as $file) |
|
131 | + foreach ($files as $file) |
|
132 | 132 | { |
133 | - if($file != '.' && $file != '..') |
|
133 | + if ($file != '.' && $file != '..') |
|
134 | 134 | { |
135 | 135 | $xmlObj = simplexml_load_file($path.$file); |
136 | - foreach($xmlObj->children() as $rule) |
|
136 | + foreach ($xmlObj->children() as $rule) |
|
137 | 137 | { |
138 | 138 | $rules[] = new self($rule); |
139 | 139 | } |
@@ -113,9 +113,9 @@ |
||
113 | 113 | if($name != 'TargetValue') |
114 | 114 | { |
115 | 115 | $this->$name = $val; |
116 | + } else { |
|
117 | + $this->$name = filter_var($val, FILTER_VALIDATE_BOOLEAN); |
|
116 | 118 | } |
117 | - else |
|
118 | - $this->$name = filter_var($val, FILTER_VALIDATE_BOOLEAN); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function __construct(\SimpleXMLElement $xmlData) |
70 | 70 | { |
71 | - if($xmlData !== null) |
|
71 | + if ($xmlData !== null) |
|
72 | 72 | { |
73 | 73 | foreach ($xmlData->children() as $child) |
74 | 74 | { |
@@ -84,10 +84,10 @@ discard block |
||
84 | 84 | */ |
85 | 85 | public static function loadFromFile() |
86 | 86 | { |
87 | - $path = str_replace('src','data',__DIR__).'/deviceModels.xml'; |
|
87 | + $path = str_replace('src', 'data', __DIR__).'/deviceModels.xml'; |
|
88 | 88 | $models = array(); |
89 | 89 | $xmlObj = simplexml_load_file($path); |
90 | - foreach($xmlObj->children() as $rule) |
|
90 | + foreach ($xmlObj->children() as $rule) |
|
91 | 91 | { |
92 | 92 | $models[] = new self($rule); |
93 | 93 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | { |
20 | 20 | if ($pathToData == 'auto') |
21 | 21 | { |
22 | - $pathToData = str_replace('src', 'data', __DIR__) . '/'; |
|
22 | + $pathToData = str_replace('src', 'data', __DIR__).'/'; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | if (self::$_xmlData === null) |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | $xml = array('Robot', 'Browser', 'Device', 'OS'); |
28 | 28 | $xmlData = array(); |
29 | 29 | foreach ($xml as $name) { |
30 | - $xmlData[$name] = simplexml_load_file($pathToData . strtolower($name) . '.xml'); |
|
30 | + $xmlData[$name] = simplexml_load_file($pathToData.strtolower($name).'.xml'); |
|
31 | 31 | } |
32 | 32 | self::$_xmlData = $xmlData; |
33 | 33 | self::$isInitialized = true; |
34 | 34 | } |
35 | 35 | } |
36 | 36 | |
37 | - public static function analyse($uaString='UA') |
|
37 | + public static function analyse($uaString = 'UA') |
|
38 | 38 | { |
39 | 39 | $ua = $uaString; |
40 | - if($uaString == 'UA') |
|
40 | + if ($uaString == 'UA') |
|
41 | 41 | { |
42 | 42 | $ua = $_SERVER['HTTP_USER_AGENT']; |
43 | 43 | } |
44 | 44 | |
45 | - if(!self::$isInitialized) |
|
45 | + if (!self::$isInitialized) |
|
46 | 46 | self::initialize(); |
47 | 47 | $xml = self::$_xmlData; |
48 | 48 | |
@@ -50,20 +50,20 @@ discard block |
||
50 | 50 | $detectorResult->uaString = $ua; |
51 | 51 | $ns = '\\EndorphinStudio\\Detector\\'; |
52 | 52 | |
53 | - foreach($xml as $key => $item) |
|
53 | + foreach ($xml as $key => $item) |
|
54 | 54 | { |
55 | - $data = self::analysePart($xml,$key,$ua); |
|
55 | + $data = self::analysePart($xml, $key, $ua); |
|
56 | 56 | $classname = $ns.$key; |
57 | - if($data !== null) |
|
57 | + if ($data !== null) |
|
58 | 58 | { |
59 | 59 | $object = new $classname($data); |
60 | - if($key == 'OS' || $key == 'Browser') |
|
60 | + if ($key == 'OS' || $key == 'Browser') |
|
61 | 61 | { |
62 | 62 | $object->setVersion(self::getVersion($data, $ua)); |
63 | 63 | } |
64 | - if($key == 'Robot') |
|
64 | + if ($key == 'Robot') |
|
65 | 65 | { |
66 | - if($object->getName() != D_NA) |
|
66 | + if ($object->getName() != D_NA) |
|
67 | 67 | { |
68 | 68 | $detectorResult->isBot = true; |
69 | 69 | } |
@@ -88,13 +88,13 @@ discard block |
||
88 | 88 | * @param string $uaString User agent |
89 | 89 | * @return \SimpleXMLElement xml element |
90 | 90 | */ |
91 | - private static function analysePart($xmlData,$key,$uaString) |
|
91 | + private static function analysePart($xmlData, $key, $uaString) |
|
92 | 92 | { |
93 | 93 | $data = $xmlData[$key]->data; |
94 | - foreach($data as $xmlItem) |
|
94 | + foreach ($data as $xmlItem) |
|
95 | 95 | { |
96 | 96 | $pattern = '/'.$xmlItem->pattern.'/'; |
97 | - if(preg_match($pattern,$uaString)) |
|
97 | + if (preg_match($pattern, $uaString)) |
|
98 | 98 | { |
99 | 99 | return $xmlItem; |
100 | 100 | } |
@@ -107,21 +107,21 @@ discard block |
||
107 | 107 | * @param string $uaString User agent |
108 | 108 | * @return string Version |
109 | 109 | */ |
110 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
110 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
111 | 111 | { |
112 | - if($xmlItem !== null) |
|
112 | + if ($xmlItem !== null) |
|
113 | 113 | { |
114 | - foreach($xmlItem->children() as $node) |
|
114 | + foreach ($xmlItem->children() as $node) |
|
115 | 115 | { |
116 | - if($node->getName() == 'versionPattern') |
|
116 | + if ($node->getName() == 'versionPattern') |
|
117 | 117 | { |
118 | 118 | $vPattern = $node->__toString(); |
119 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
119 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
120 | 120 | $uaString = str_replace(' NT', '', $uaString); |
121 | 121 | if (preg_match($version, $uaString)) { |
122 | 122 | preg_match($version, $uaString, $v); |
123 | 123 | $version = $v[0]; |
124 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
124 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
125 | 125 | $version = str_replace(';', '', $version); |
126 | 126 | $version = str_replace(' ', '', $version); |
127 | 127 | $version = str_replace('/', '', $version); |
@@ -163,7 +163,7 @@ discard block |
||
163 | 163 | '10.0' => '10' |
164 | 164 | ); |
165 | 165 | |
166 | - if(array_key_exists(strval($version),$versions)) |
|
166 | + if (array_key_exists(strval($version), $versions)) |
|
167 | 167 | return $versions[strval($version)]; |
168 | 168 | else |
169 | 169 | return D_NA; |
@@ -176,14 +176,14 @@ discard block |
||
176 | 176 | private static function checkRules(DetectorResult $result) |
177 | 177 | { |
178 | 178 | $Rules = DetectorRule::loadRulesFromFile(); |
179 | - foreach($Rules as $rule) |
|
179 | + foreach ($Rules as $rule) |
|
180 | 180 | { |
181 | 181 | $objectType = $rule->getObjectType(); |
182 | 182 | $objectProperty = $rule->getObjectProperty(); |
183 | 183 | $targetType = $rule->getTargetType(); |
184 | 184 | $targetValue = $rule->isTargetValue(); |
185 | 185 | $func = 'get'.$objectProperty; |
186 | - if($result->$objectType !== null) |
|
186 | + if ($result->$objectType !== null) |
|
187 | 187 | { |
188 | 188 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
189 | 189 | $result->$targetType = $targetValue; |
@@ -197,16 +197,16 @@ discard block |
||
197 | 197 | private static function checkModelName(DetectorResult $result) |
198 | 198 | { |
199 | 199 | $models = DeviceModel::loadFromFile(); |
200 | - foreach($models as $model) |
|
200 | + foreach ($models as $model) |
|
201 | 201 | { |
202 | - if($model->getDeviceName() === $result->Device->getName()) |
|
202 | + if ($model->getDeviceName() === $result->Device->getName()) |
|
203 | 203 | { |
204 | 204 | $pattern = '/'.$model->getPattern().'/'; |
205 | - preg_match($pattern,$result->uaString,$match); |
|
205 | + preg_match($pattern, $result->uaString, $match); |
|
206 | 206 | $result->Device->setModelName($match[1]); |
207 | 207 | } |
208 | 208 | } |
209 | 209 | return $result; |
210 | 210 | } |
211 | 211 | } |
212 | -define('D_NA','N\A'); |
|
212 | +define('D_NA', 'N\A'); |
@@ -42,8 +42,9 @@ discard block |
||
42 | 42 | $ua = $_SERVER['HTTP_USER_AGENT']; |
43 | 43 | } |
44 | 44 | |
45 | - if(!self::$isInitialized) |
|
46 | - self::initialize(); |
|
45 | + if(!self::$isInitialized) { |
|
46 | + self::initialize(); |
|
47 | + } |
|
47 | 48 | $xml = self::$_xmlData; |
48 | 49 | |
49 | 50 | $detectorResult = new DetectorResult(); |
@@ -68,8 +69,7 @@ discard block |
||
68 | 69 | $detectorResult->isBot = true; |
69 | 70 | } |
70 | 71 | } |
71 | - } |
|
72 | - else |
|
72 | + } else |
|
73 | 73 | { |
74 | 74 | $object = $classname::initEmpty(); |
75 | 75 | } |
@@ -163,10 +163,11 @@ discard block |
||
163 | 163 | '10.0' => '10' |
164 | 164 | ); |
165 | 165 | |
166 | - if(array_key_exists(strval($version),$versions)) |
|
167 | - return $versions[strval($version)]; |
|
168 | - else |
|
169 | - return D_NA; |
|
166 | + if(array_key_exists(strval($version),$versions)) { |
|
167 | + return $versions[strval($version)]; |
|
168 | + } else { |
|
169 | + return D_NA; |
|
170 | + } |
|
170 | 171 | } |
171 | 172 | |
172 | 173 | /** |