@@ -25,8 +25,7 @@ |
||
| 25 | 25 | { |
| 26 | 26 | $this->Name = 'Desktop'; |
| 27 | 27 | $this->Type = 'desktop'; |
| 28 | - } |
|
| 29 | - else |
|
| 28 | + } else |
|
| 30 | 29 | { |
| 31 | 30 | parent::__construct($xmlData); |
| 32 | 31 | |
@@ -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 | |
@@ -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'); |
|
@@ -72,7 +72,7 @@ |
||
| 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 | { |
@@ -72,7 +72,7 @@ discard block |
||
| 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 | { |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | break; |
| 87 | 87 | case 'isse': |
| 88 | 88 | $val = $child->__toString(); |
| 89 | - if($val == 'true') |
|
| 89 | + if ($val == 'true') |
|
| 90 | 90 | { |
| 91 | 91 | $this->setSearchEngine(true); |
| 92 | 92 | } |
@@ -89,9 +89,9 @@ |
||
| 89 | 89 | if($val == 'true') |
| 90 | 90 | { |
| 91 | 91 | $this->setSearchEngine(true); |
| 92 | + } else { |
|
| 93 | + $this->setSearchEngine(false); |
|
| 92 | 94 | } |
| 93 | - else |
|
| 94 | - $this->setSearchEngine(false); |
|
| 95 | 95 | break; |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -104,7 +104,7 @@ 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 | switch ($child->getName()) |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | break; |
| 124 | 124 | case 'targetProperty': |
| 125 | 125 | $boolVal = $child->__toString(); |
| 126 | - if($boolVal == 'true') |
|
| 126 | + if ($boolVal == 'true') |
|
| 127 | 127 | { |
| 128 | 128 | $this->TargetValue = true; |
| 129 | 129 | } |
@@ -142,15 +142,15 @@ discard block |
||
| 142 | 142 | */ |
| 143 | 143 | public static function loadRulesFromFile() |
| 144 | 144 | { |
| 145 | - $path = str_replace('src','data',__DIR__).'/rules/'; |
|
| 145 | + $path = str_replace('src', 'data', __DIR__).'/rules/'; |
|
| 146 | 146 | $files = scandir($path); |
| 147 | 147 | $rules = array(); |
| 148 | - foreach($files as $file) |
|
| 148 | + foreach ($files as $file) |
|
| 149 | 149 | { |
| 150 | - if($file != '.' && $file != '..') |
|
| 150 | + if ($file != '.' && $file != '..') |
|
| 151 | 151 | { |
| 152 | 152 | $xmlObj = simplexml_load_file($path.$file); |
| 153 | - foreach($xmlObj->children() as $rule) |
|
| 153 | + foreach ($xmlObj->children() as $rule) |
|
| 154 | 154 | { |
| 155 | 155 | $rules[] = new self($rule); |
| 156 | 156 | } |
@@ -126,8 +126,7 @@ |
||
| 126 | 126 | if($boolVal == 'true') |
| 127 | 127 | { |
| 128 | 128 | $this->TargetValue = true; |
| 129 | - } |
|
| 130 | - else |
|
| 129 | + } else |
|
| 131 | 130 | { |
| 132 | 131 | $this->TargetValue = false; |
| 133 | 132 | } |
@@ -52,26 +52,26 @@ discard block |
||
| 52 | 52 | * Detector constructor. |
| 53 | 53 | * @param string $pathToData Path to directory with xml data files |
| 54 | 54 | */ |
| 55 | - private function __construct($pathToData='auto') |
|
| 55 | + private function __construct($pathToData = 'auto') |
|
| 56 | 56 | { |
| 57 | - if($pathToData == 'auto') |
|
| 57 | + if ($pathToData == 'auto') |
|
| 58 | 58 | { |
| 59 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
| 59 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - $xml = array('Robot','Browser','Device','OS'); |
|
| 62 | + $xml = array('Robot', 'Browser', 'Device', 'OS'); |
|
| 63 | 63 | $xmlData = array(); |
| 64 | - foreach($xml as $name) |
|
| 64 | + foreach ($xml as $name) |
|
| 65 | 65 | { |
| 66 | 66 | $xmlData[$name] = simplexml_load_file($this->getPathToData().strtolower($name).'.xml'); |
| 67 | 67 | } |
| 68 | 68 | $this->setXmlData($xmlData); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public static function analyse($uaString='UA', $pathToData='auto') |
|
| 71 | + public static function analyse($uaString = 'UA', $pathToData = 'auto') |
|
| 72 | 72 | { |
| 73 | 73 | $ua = $uaString; |
| 74 | - if($uaString == 'UA') |
|
| 74 | + if ($uaString == 'UA') |
|
| 75 | 75 | { |
| 76 | 76 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 77 | 77 | } |
@@ -79,22 +79,22 @@ discard block |
||
| 79 | 79 | $detector = new Detector($pathToData); |
| 80 | 80 | $xml = $detector->getXmlData(); |
| 81 | 81 | $data = array(); |
| 82 | - foreach($xml as $key => $item) |
|
| 82 | + foreach ($xml as $key => $item) |
|
| 83 | 83 | { |
| 84 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
| 84 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | $detectorResult = new DetectorResult(); |
| 88 | 88 | $detectorResult->uaString = $ua; |
| 89 | 89 | $ns = '\\EndorphinStudio\\Detector\\'; |
| 90 | 90 | |
| 91 | - foreach($data as $key => $result) |
|
| 91 | + foreach ($data as $key => $result) |
|
| 92 | 92 | { |
| 93 | 93 | $classname = $ns.$key; |
| 94 | - if($result !== null) |
|
| 94 | + if ($result !== null) |
|
| 95 | 95 | { |
| 96 | 96 | $object = new $classname($result); |
| 97 | - if($key == 'Os' || $key == 'Browser') |
|
| 97 | + if ($key == 'Os' || $key == 'Browser') |
|
| 98 | 98 | { |
| 99 | 99 | $object->setVersion(self::getVersion($result, $ua)); |
| 100 | 100 | } |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | * @param string $uaString User agent |
| 118 | 118 | * @return \SimpleXMLElement xml element |
| 119 | 119 | */ |
| 120 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 120 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 121 | 121 | { |
| 122 | 122 | $data = $xmlData[$key]->data; |
| 123 | - foreach($data as $xmlItem) |
|
| 123 | + foreach ($data as $xmlItem) |
|
| 124 | 124 | { |
| 125 | 125 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 126 | - if(preg_match($pattern,$uaString)) |
|
| 126 | + if (preg_match($pattern, $uaString)) |
|
| 127 | 127 | { |
| 128 | 128 | return $xmlItem; |
| 129 | 129 | } |
@@ -136,21 +136,21 @@ discard block |
||
| 136 | 136 | * @param string $uaString User agent |
| 137 | 137 | * @return string Version |
| 138 | 138 | */ |
| 139 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 139 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 140 | 140 | { |
| 141 | - if($xmlItem !== null) |
|
| 141 | + if ($xmlItem !== null) |
|
| 142 | 142 | { |
| 143 | - foreach($xmlItem->children() as $node) |
|
| 143 | + foreach ($xmlItem->children() as $node) |
|
| 144 | 144 | { |
| 145 | - if($node->getName() == 'versionPattern') |
|
| 145 | + if ($node->getName() == 'versionPattern') |
|
| 146 | 146 | { |
| 147 | 147 | $vPattern = $node->__toString(); |
| 148 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 148 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 149 | 149 | $uaString = str_replace(' NT', '', $uaString); |
| 150 | 150 | if (preg_match($version, $uaString)) { |
| 151 | 151 | preg_match($version, $uaString, $v); |
| 152 | 152 | $version = $v[0]; |
| 153 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 153 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 154 | 154 | $version = str_replace(';', '', $version); |
| 155 | 155 | $version = str_replace(' ', '', $version); |
| 156 | 156 | $version = str_replace('/', '', $version); |
@@ -194,14 +194,14 @@ discard block |
||
| 194 | 194 | private static function checkRules(DetectorResult $result) |
| 195 | 195 | { |
| 196 | 196 | $Rules = DetectorRule::loadRulesFromFile(); |
| 197 | - foreach($Rules as $rule) |
|
| 197 | + foreach ($Rules as $rule) |
|
| 198 | 198 | { |
| 199 | 199 | $objectType = $rule->getObjectType(); |
| 200 | 200 | $objectProperty = $rule->getObjectProperty(); |
| 201 | 201 | $targetType = $rule->getTargetType(); |
| 202 | 202 | $targetValue = $rule->isTargetValue(); |
| 203 | 203 | $func = 'get'.$objectProperty; |
| 204 | - if($result->$objectType !== null) |
|
| 204 | + if ($result->$objectType !== null) |
|
| 205 | 205 | { |
| 206 | 206 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 207 | 207 | $result->$targetType = $targetValue; |
@@ -212,4 +212,4 @@ discard block |
||
| 212 | 212 | return $result; |
| 213 | 213 | } |
| 214 | 214 | } |
| 215 | -define('D_NA','N\A'); |
|
| 215 | +define('D_NA', 'N\A'); |
|
@@ -98,8 +98,7 @@ |
||
| 98 | 98 | { |
| 99 | 99 | $object->setVersion(self::getVersion($result, $ua)); |
| 100 | 100 | } |
| 101 | - } |
|
| 102 | - else |
|
| 101 | + } else |
|
| 103 | 102 | { |
| 104 | 103 | $object = $classname::initEmpty(); |
| 105 | 104 | } |