@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | { |
| 19 | 19 | if ($pathToData == 'auto') |
| 20 | 20 | { |
| 21 | - $pathToData = str_replace('src', 'data', __DIR__) . '/'; |
|
| 21 | + $pathToData = str_replace('src', 'data', __DIR__).'/'; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (self::$xmlData === null) |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | $xml = array('Robot', 'Browser', 'Device', 'OS'); |
| 27 | 27 | $xmlData = array(); |
| 28 | 28 | foreach ($xml as $name) { |
| 29 | - $xmlData[$name] = simplexml_load_file($pathToData . strtolower($name) . '.xml'); |
|
| 29 | + $xmlData[$name] = simplexml_load_file($pathToData.strtolower($name).'.xml'); |
|
| 30 | 30 | } |
| 31 | 31 | self::$xmlData = $xmlData; |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public static function analyse($uaString='UA') |
|
| 35 | + public static function analyse($uaString = 'UA') |
|
| 36 | 36 | { |
| 37 | 37 | $ua = $uaString; |
| 38 | - if($uaString == 'UA') |
|
| 38 | + if ($uaString == 'UA') |
|
| 39 | 39 | { |
| 40 | 40 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 41 | 41 | } |
@@ -47,20 +47,20 @@ discard block |
||
| 47 | 47 | $detectorResult->uaString = $ua; |
| 48 | 48 | $ns = '\\EndorphinStudio\\Detector\\'; |
| 49 | 49 | |
| 50 | - foreach($xml as $key => $item) |
|
| 50 | + foreach ($xml as $key => $item) |
|
| 51 | 51 | { |
| 52 | - $data = self::analysePart($xml,$key,$ua); |
|
| 52 | + $data = self::analysePart($xml, $key, $ua); |
|
| 53 | 53 | $classname = $ns.$key; |
| 54 | - if($data !== null) |
|
| 54 | + if ($data !== null) |
|
| 55 | 55 | { |
| 56 | 56 | $object = new $classname($data); |
| 57 | - if($key == 'OS' || $key == 'Browser') |
|
| 57 | + if ($key == 'OS' || $key == 'Browser') |
|
| 58 | 58 | { |
| 59 | 59 | $object->setVersion(self::getVersion($data, $ua)); |
| 60 | 60 | } |
| 61 | - if($key == 'Robot') |
|
| 61 | + if ($key == 'Robot') |
|
| 62 | 62 | { |
| 63 | - if($object->getName() != D_NA) |
|
| 63 | + if ($object->getName() != D_NA) |
|
| 64 | 64 | { |
| 65 | 65 | $detectorResult->isBot = true; |
| 66 | 66 | } |
@@ -84,13 +84,13 @@ discard block |
||
| 84 | 84 | * @param string $uaString User agent |
| 85 | 85 | * @return \SimpleXMLElement xml element |
| 86 | 86 | */ |
| 87 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 87 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 88 | 88 | { |
| 89 | 89 | $data = $xmlData[$key]->data; |
| 90 | - foreach($data as $xmlItem) |
|
| 90 | + foreach ($data as $xmlItem) |
|
| 91 | 91 | { |
| 92 | 92 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 93 | - if(preg_match($pattern,$uaString)) |
|
| 93 | + if (preg_match($pattern, $uaString)) |
|
| 94 | 94 | { |
| 95 | 95 | return $xmlItem; |
| 96 | 96 | } |
@@ -103,21 +103,21 @@ discard block |
||
| 103 | 103 | * @param string $uaString User agent |
| 104 | 104 | * @return string Version |
| 105 | 105 | */ |
| 106 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 106 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 107 | 107 | { |
| 108 | - if($xmlItem !== null) |
|
| 108 | + if ($xmlItem !== null) |
|
| 109 | 109 | { |
| 110 | - foreach($xmlItem->children() as $node) |
|
| 110 | + foreach ($xmlItem->children() as $node) |
|
| 111 | 111 | { |
| 112 | - if($node->getName() == 'versionPattern') |
|
| 112 | + if ($node->getName() == 'versionPattern') |
|
| 113 | 113 | { |
| 114 | 114 | $vPattern = $node->__toString(); |
| 115 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 115 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 116 | 116 | $uaString = str_replace(' NT', '', $uaString); |
| 117 | 117 | if (preg_match($version, $uaString)) { |
| 118 | 118 | preg_match($version, $uaString, $v); |
| 119 | 119 | $version = $v[0]; |
| 120 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 120 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 121 | 121 | $version = str_replace(';', '', $version); |
| 122 | 122 | $version = str_replace(' ', '', $version); |
| 123 | 123 | $version = str_replace('/', '', $version); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | '10.0' => '10' |
| 160 | 160 | ); |
| 161 | 161 | |
| 162 | - if(array_key_exists(strval($version),$versions)) |
|
| 162 | + if (array_key_exists(strval($version), $versions)) |
|
| 163 | 163 | return $versions[strval($version)]; |
| 164 | 164 | else |
| 165 | 165 | return D_NA; |
@@ -172,14 +172,14 @@ discard block |
||
| 172 | 172 | private static function checkRules(DetectorResult $result) |
| 173 | 173 | { |
| 174 | 174 | $Rules = DetectorRule::loadRulesFromFile(); |
| 175 | - foreach($Rules as $rule) |
|
| 175 | + foreach ($Rules as $rule) |
|
| 176 | 176 | { |
| 177 | 177 | $objectType = $rule->getObjectType(); |
| 178 | 178 | $objectProperty = $rule->getObjectProperty(); |
| 179 | 179 | $targetType = $rule->getTargetType(); |
| 180 | 180 | $targetValue = $rule->isTargetValue(); |
| 181 | 181 | $func = 'get'.$objectProperty; |
| 182 | - if($result->$objectType !== null) |
|
| 182 | + if ($result->$objectType !== null) |
|
| 183 | 183 | { |
| 184 | 184 | if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) { |
| 185 | 185 | $result->$targetType = $targetValue; |
@@ -190,4 +190,4 @@ discard block |
||
| 190 | 190 | return $result; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | -define('D_NA','N\A'); |
|
| 193 | +define('D_NA', 'N\A'); |
|