@@ -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 | } |