@@ -164,7 +164,7 @@ |
||
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
| 167 | - * @param $version Windows number version |
|
| 167 | + * @param string $version Windows number version |
|
| 168 | 168 | * @return string Windows version |
| 169 | 169 | */ |
| 170 | 170 | private static function getWindowsVersion($version) |
@@ -53,26 +53,26 @@ discard block |
||
| 53 | 53 | * Detector constructor. |
| 54 | 54 | * @param string $pathToData Path to directory with xml data files |
| 55 | 55 | */ |
| 56 | - private function __construct($pathToData='auto') |
|
| 56 | + private function __construct($pathToData = 'auto') |
|
| 57 | 57 | { |
| 58 | - if($pathToData == 'auto') |
|
| 58 | + if ($pathToData == 'auto') |
|
| 59 | 59 | { |
| 60 | - $this->setPathToData(str_replace('src','data',__DIR__).'/'); |
|
| 60 | + $this->setPathToData(str_replace('src', 'data', __DIR__).'/'); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - $xml = array('robot','browser','device','os'); |
|
| 63 | + $xml = array('robot', 'browser', 'device', 'os'); |
|
| 64 | 64 | $xmlData = array(); |
| 65 | - foreach($xml as $name) |
|
| 65 | + foreach ($xml as $name) |
|
| 66 | 66 | { |
| 67 | 67 | $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml'); |
| 68 | 68 | } |
| 69 | 69 | $this->setXmlData($xmlData); |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - public static function analyse($uaString='UA', $pathToData='auto') |
|
| 72 | + public static function analyse($uaString = 'UA', $pathToData = 'auto') |
|
| 73 | 73 | { |
| 74 | 74 | $ua = $uaString; |
| 75 | - if($uaString == 'UA') |
|
| 75 | + if ($uaString == 'UA') |
|
| 76 | 76 | { |
| 77 | 77 | $ua = $_SERVER['HTTP_USER_AGENT']; |
| 78 | 78 | } |
@@ -80,23 +80,23 @@ discard block |
||
| 80 | 80 | $detector = new Detector($pathToData); |
| 81 | 81 | $xml = $detector->getXmlData(); |
| 82 | 82 | $data = array(); |
| 83 | - foreach($xml as $key => $item) |
|
| 83 | + foreach ($xml as $key => $item) |
|
| 84 | 84 | { |
| 85 | - $data[$key] = self::analysePart($xml,$key,$ua); |
|
| 85 | + $data[$key] = self::analysePart($xml, $key, $ua); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $detectorResult = new DetectorResult(); |
| 89 | 89 | $detectorResult->uaString = $ua; |
| 90 | 90 | $isRobot = false; |
| 91 | 91 | |
| 92 | - foreach($data as $key => $result) |
|
| 92 | + foreach ($data as $key => $result) |
|
| 93 | 93 | { |
| 94 | - if(!$isRobot) |
|
| 94 | + if (!$isRobot) |
|
| 95 | 95 | { |
| 96 | 96 | switch ($key) |
| 97 | 97 | { |
| 98 | 98 | case 'robot': |
| 99 | - if($result !== null) |
|
| 99 | + if ($result !== null) |
|
| 100 | 100 | { |
| 101 | 101 | $robot = new Robot($result); |
| 102 | 102 | $detectorResult->Robot = $robot; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | break; |
| 108 | 108 | case 'os': |
| 109 | - if($result !== null) |
|
| 109 | + if ($result !== null) |
|
| 110 | 110 | { |
| 111 | 111 | $os = new OS($result); |
| 112 | 112 | $os->setVersion(self::getVersion($result, $ua)); |
@@ -114,14 +114,14 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | break; |
| 116 | 116 | case 'device': |
| 117 | - if($result !== null) |
|
| 117 | + if ($result !== null) |
|
| 118 | 118 | { |
| 119 | 119 | $device = new Device($result); |
| 120 | 120 | $detectorResult->Device = $device; |
| 121 | 121 | } |
| 122 | 122 | break; |
| 123 | 123 | case 'browser': |
| 124 | - if($result !== null) |
|
| 124 | + if ($result !== null) |
|
| 125 | 125 | { |
| 126 | 126 | $browser = new Browser($result); |
| 127 | 127 | $browser->setVersion(self::getVersion($result, $ua)); |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @param string $uaString User agent |
| 142 | 142 | * @return \SimpleXMLElement xml element |
| 143 | 143 | */ |
| 144 | - private static function analysePart($xmlData,$key,$uaString) |
|
| 144 | + private static function analysePart($xmlData, $key, $uaString) |
|
| 145 | 145 | { |
| 146 | 146 | $data = $xmlData[$key]->data; |
| 147 | - foreach($data as $xmlItem) |
|
| 147 | + foreach ($data as $xmlItem) |
|
| 148 | 148 | { |
| 149 | 149 | $pattern = '/'.$xmlItem->pattern.'/'; |
| 150 | - if(preg_match($pattern,$uaString)) |
|
| 150 | + if (preg_match($pattern, $uaString)) |
|
| 151 | 151 | { |
| 152 | 152 | return $xmlItem; |
| 153 | 153 | } |
@@ -160,19 +160,19 @@ discard block |
||
| 160 | 160 | * @param string $uaString User agent |
| 161 | 161 | * @return string Version |
| 162 | 162 | */ |
| 163 | - private static function getVersion(\SimpleXMLElement $xmlItem,$uaString) |
|
| 163 | + private static function getVersion(\SimpleXMLElement $xmlItem, $uaString) |
|
| 164 | 164 | { |
| 165 | - if($xmlItem !== null) |
|
| 165 | + if ($xmlItem !== null) |
|
| 166 | 166 | { |
| 167 | - if(isset($xmlItem->versionPattern)) |
|
| 167 | + if (isset($xmlItem->versionPattern)) |
|
| 168 | 168 | { |
| 169 | 169 | $vPattern = $xmlItem->versionPattern; |
| 170 | - $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/'; |
|
| 170 | + $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/'; |
|
| 171 | 171 | $uaString = str_replace(' NT', '', $uaString); |
| 172 | 172 | if (preg_match($version, $uaString)) { |
| 173 | 173 | preg_match($version, $uaString, $v); |
| 174 | 174 | $version = $v[0]; |
| 175 | - $version = preg_replace('/' . $vPattern . '/', '', $version); |
|
| 175 | + $version = preg_replace('/'.$vPattern.'/', '', $version); |
|
| 176 | 176 | $version = str_replace(';', '', $version); |
| 177 | 177 | $version = str_replace(' ', '', $version); |
| 178 | 178 | $version = str_replace('/', '', $version); |
@@ -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) |
|
| 24 | + if ($xmlData === null) |
|
| 25 | 25 | { |
| 26 | 26 | $this->Name = 'Desktop'; |
| 27 | 27 | $this->Type = 'desktop'; |
@@ -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'); |
|
@@ -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 | { |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | public function testFirefox() |
| 19 | 19 | { |
| 20 | - $this->assertEquals('Firefox',Detector::analyse('Mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0 ')->Browser->getName()); |
|
| 20 | + $this->assertEquals('Firefox', Detector::analyse('Mozilla/5.0 (Windows NT 6.3; WOW64; rv:46.0) Gecko/20100101 Firefox/46.0 ')->Browser->getName()); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | public function testOpera() |
| 27 | 27 | { |
| 28 | - $this->assertEquals('Opera',Detector::analyse('Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16')->Browser->getName()); |
|
| 28 | + $this->assertEquals('Opera', Detector::analyse('Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16')->Browser->getName()); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | |
@@ -7,15 +7,15 @@ discard block |
||
| 7 | 7 | * @project browser-detector |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -$vendor = realpath(__DIR__ . '/../vendor/'); |
|
| 10 | +$vendor = realpath(__DIR__.'/../vendor/'); |
|
| 11 | 11 | |
| 12 | -define('__SRC__',str_replace('tests','src',__DIR__)); |
|
| 13 | -if (file_exists($vendor . '/autoload.php')) { |
|
| 14 | - require $vendor . '/autoload.php'; |
|
| 12 | +define('__SRC__', str_replace('tests', 'src', __DIR__)); |
|
| 13 | +if (file_exists($vendor.'/autoload.php')) { |
|
| 14 | + require $vendor.'/autoload.php'; |
|
| 15 | 15 | } else { |
| 16 | - $vendor = realpath(__DIR__ . '/../../../'); |
|
| 17 | - if (file_exists($vendor . '/autoload.php')) { |
|
| 18 | - require $vendor . '/autoload.php'; |
|
| 16 | + $vendor = realpath(__DIR__.'/../../../'); |
|
| 17 | + if (file_exists($vendor.'/autoload.php')) { |
|
| 18 | + require $vendor.'/autoload.php'; |
|
| 19 | 19 | } else { |
| 20 | 20 | throw new Exception('Unable to load dependencies'); |
| 21 | 21 | } |
@@ -28,12 +28,12 @@ discard block |
||
| 28 | 28 | $loader->addPrefix('EndorphinStudio\\Detector', __SRC__); |
| 29 | 29 | $loader->register(); |
| 30 | 30 | |
| 31 | -function testUaList($object,$detectorProperty,$property,$uaList,$expectedValue) |
|
| 31 | +function testUaList($object, $detectorProperty, $property, $uaList, $expectedValue) |
|
| 32 | 32 | { |
| 33 | - foreach($uaList as $ua) |
|
| 33 | + foreach ($uaList as $ua) |
|
| 34 | 34 | { |
| 35 | 35 | $obj = Detector::analyse($ua)->$detectorProperty; |
| 36 | 36 | $func = 'get'.$property; |
| 37 | - $object->assertEquals($expectedValue,$obj->$func()); |
|
| 37 | + $object->assertEquals($expectedValue, $obj->$func()); |
|
| 38 | 38 | } |
| 39 | 39 | } |
| 40 | 40 | \ No newline at end of file |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | 'Tiny Tiny RSS/1.10 (http://tt-rss.org/)' |
| 23 | 23 | ); |
| 24 | 24 | |
| 25 | - testUaList($this,'Robot','Name',$ualist,'Tiny RSS'); |
|
| 25 | + testUaList($this, 'Robot', 'Name', $ualist, 'Tiny RSS'); |
|
| 26 | 26 | } |
| 27 | 27 | /** |
| 28 | 28 | * Test Google Bots |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | 'Mediapartners-Google' |
| 43 | 43 | ); |
| 44 | 44 | |
| 45 | - testUaList($this,'Robot','Owner',$ualist,'Google Inc.'); |
|
| 45 | + testUaList($this, 'Robot', 'Owner', $ualist, 'Google Inc.'); |
|
| 46 | 46 | } |
| 47 | 47 | /** |
| 48 | 48 | * Test Yandex Bots |
@@ -81,6 +81,6 @@ discard block |
||
| 81 | 81 | 'Mozilla/5.0 (compatible; YandexSpravBot/1.0; +http://yandex.com/bots)' |
| 82 | 82 | ); |
| 83 | 83 | |
| 84 | - testUaList($this,'Robot','Owner',$ualist,'Yandex LLC.'); |
|
| 84 | + testUaList($this, 'Robot', 'Owner', $ualist, 'Yandex LLC.'); |
|
| 85 | 85 | } |
| 86 | 86 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | 'Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3' |
| 22 | 22 | ); |
| 23 | 23 | |
| 24 | - testUaList($this,'Device','Name',$ualist,'iPhone'); |
|
| 24 | + testUaList($this, 'Device', 'Name', $ualist, 'iPhone'); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public function testIPad() |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | 'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206' |
| 34 | 34 | ); |
| 35 | 35 | |
| 36 | - testUaList($this,'Device','Name',$ualist,'iPad'); |
|
| 36 | + testUaList($this, 'Device', 'Name', $ualist, 'iPad'); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function testLumia() |
@@ -45,6 +45,6 @@ discard block |
||
| 45 | 45 | 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)' |
| 46 | 46 | ); |
| 47 | 47 | |
| 48 | - testUaList($this,'Device','Name',$ualist,'Lumia'); |
|
| 48 | + testUaList($this, 'Device', 'Name', $ualist, 'Lumia'); |
|
| 49 | 49 | } |
| 50 | 50 | } |