Completed
Branch 3.0.0 (3f0ab7)
by Serhii
03:15
created
src/Detector.php 4 patches
Doc Comments   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     }
217 217
 
218 218
     /**
219
-     * @param $version Windows number version
219
+     * @param string $version Windows number version
220 220
      * @return string Windows version
221 221
      */
222 222
     private static function getWindowsVersion($version)
@@ -235,7 +235,6 @@  discard block
 block discarded – undo
235 235
     }
236 236
 
237 237
     /**
238
-     * @param DetectorResult $DetectorResult Detector result
239 238
      * @return DetectorResult Final result
240 239
      */
241 240
     private function ckeckRules(\EndorphinStudio\Detector\DetectorResult $result)
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,6 @@
 block discarded – undo
10 10
 namespace EndorphinStudio\Detector;
11 11
 
12 12
 
13
-use Composer\DependencyResolver\Rule;
14
-
15 13
 class Detector
16 14
 {
17 15
     /**
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
      * Detector constructor.
58 58
      * @param string $pathToData Path to directory with xml data files
59 59
      */
60
-    private function __construct($pathToData='auto')
60
+    private function __construct($pathToData = 'auto')
61 61
     {
62
-        if($pathToData == 'auto')
62
+        if ($pathToData == 'auto')
63 63
         {
64
-            $this->setPathToData(str_replace('src','data',__DIR__).'/');
64
+            $this->setPathToData(str_replace('src', 'data', __DIR__).'/');
65 65
         }
66 66
 
67
-        $xml = array('robot','browser','device','os');
67
+        $xml = array('robot', 'browser', 'device', 'os');
68 68
         $xmlData = array();
69
-        foreach($xml as $name)
69
+        foreach ($xml as $name)
70 70
         {
71 71
             $xmlData[$name] = simplexml_load_file($this->getPathToData().$name.'.xml');
72 72
         }
@@ -75,10 +75,10 @@  discard block
 block discarded – undo
75 75
         $this->Rules = DetectorRule::loadRulesFromFile();
76 76
     }
77 77
 
78
-    public static function analyse($uaString='UA', $pathToData='auto')
78
+    public static function analyse($uaString = 'UA', $pathToData = 'auto')
79 79
     {
80 80
         $ua = $uaString;
81
-        if($uaString == 'UA')
81
+        if ($uaString == 'UA')
82 82
         {
83 83
             $ua = $_SERVER['HTTP_USER_AGENT'];
84 84
         }
@@ -86,23 +86,23 @@  discard block
 block discarded – undo
86 86
         $detector = new Detector($pathToData);
87 87
         $xml = $detector->getXmlData();
88 88
         $data = array();
89
-        foreach($xml as $key => $item)
89
+        foreach ($xml as $key => $item)
90 90
         {
91
-            $data[$key] = self::analysePart($xml,$key,$ua);
91
+            $data[$key] = self::analysePart($xml, $key, $ua);
92 92
         }
93 93
 
94 94
         $detectorResult = new DetectorResult();
95 95
         $detectorResult->uaString = $ua;
96 96
         $isRobot = false;
97 97
 
98
-        foreach($data as $key => $result)
98
+        foreach ($data as $key => $result)
99 99
         {
100
-            if(!$isRobot)
100
+            if (!$isRobot)
101 101
             {
102 102
                 switch ($key)
103 103
                 {
104 104
                     case 'robot':
105
-                        if($result !== null)
105
+                        if ($result !== null)
106 106
                         {
107 107
                             $robot = new Robot($result);
108 108
                             $detectorResult->Robot = $robot;
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
                         }
113 113
                         break;
114 114
                     case 'os':
115
-                        if($result !== null)
115
+                        if ($result !== null)
116 116
                         {
117 117
                             $os = new OS($result);
118 118
                             $os->setVersion(self::getVersion($result, $ua));
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                         }
126 126
                         break;
127 127
                     case 'device':
128
-                        if($result !== null)
128
+                        if ($result !== null)
129 129
                         {
130 130
                             $device = new Device($result);
131 131
                             $detectorResult->Device = $device;
@@ -137,7 +137,7 @@  discard block
 block discarded – undo
137 137
                         }
138 138
                         break;
139 139
                     case 'browser':
140
-                        if($result !== null)
140
+                        if ($result !== null)
141 141
                         {
142 142
                             $browser = new Browser($result);
143 143
                             $browser->setVersion(self::getVersion($result, $ua));
@@ -164,13 +164,13 @@  discard block
 block discarded – undo
164 164
      * @param string $uaString User agent
165 165
      * @return \SimpleXMLElement xml element
166 166
      */
167
-    private static function analysePart($xmlData,$key,$uaString)
167
+    private static function analysePart($xmlData, $key, $uaString)
168 168
     {
169 169
         $data = $xmlData[$key]->data;
170
-        foreach($data as $xmlItem)
170
+        foreach ($data as $xmlItem)
171 171
         {
172 172
             $pattern = '/'.$xmlItem->pattern.'/';
173
-            if(preg_match($pattern,$uaString))
173
+            if (preg_match($pattern, $uaString))
174 174
             {
175 175
                 return $xmlItem;
176 176
             }
@@ -183,21 +183,21 @@  discard block
 block discarded – undo
183 183
      * @param string $uaString User agent
184 184
      * @return string Version
185 185
      */
186
-    private static function getVersion(\SimpleXMLElement $xmlItem,$uaString)
186
+    private static function getVersion(\SimpleXMLElement $xmlItem, $uaString)
187 187
     {
188
-        if($xmlItem !== null)
188
+        if ($xmlItem !== null)
189 189
         {
190
-            foreach($xmlItem->children() as $node)
190
+            foreach ($xmlItem->children() as $node)
191 191
             {
192
-                if($node->getName() == 'versionPattern')
192
+                if ($node->getName() == 'versionPattern')
193 193
                 {
194 194
                     $vPattern = $node->__toString();
195
-                    $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/';
195
+                    $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/';
196 196
                     $uaString = str_replace(' NT', '', $uaString);
197 197
                     if (preg_match($version, $uaString)) {
198 198
                         preg_match($version, $uaString, $v);
199 199
                         $version = $v[0];
200
-                        $version = preg_replace('/' . $vPattern . '/', '', $version);
200
+                        $version = preg_replace('/'.$vPattern.'/', '', $version);
201 201
                         $version = str_replace(';', '', $version);
202 202
                         $version = str_replace(' ', '', $version);
203 203
                         $version = str_replace('/', '', $version);
@@ -240,14 +240,14 @@  discard block
 block discarded – undo
240 240
      */
241 241
     private function ckeckRules(\EndorphinStudio\Detector\DetectorResult $result)
242 242
     {
243
-        foreach($this->Rules as $rule)
243
+        foreach ($this->Rules as $rule)
244 244
         {
245 245
             $objectType = $rule->getObjectType();
246 246
             $objectProperty = $rule->getObjectProperty();
247 247
             $targetType = $rule->getTargetType();
248 248
             $targetValue = $rule->isTargetValue();
249 249
             $func = 'get'.$objectProperty;
250
-            if($result->$objectType !== null)
250
+            if ($result->$objectType !== null)
251 251
             {
252 252
                 if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) {
253 253
                     $result->$targetType = $targetValue;
@@ -258,4 +258,4 @@  discard block
 block discarded – undo
258 258
         return $result;
259 259
     }
260 260
 }
261
-define('D_NA','N\A');
262 261
\ No newline at end of file
262
+define('D_NA', 'N\A');
263 263
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -117,8 +117,7 @@  discard block
 block discarded – undo
117 117
                             $os = new OS($result);
118 118
                             $os->setVersion(self::getVersion($result, $ua));
119 119
                             $detectorResult->OS = $os;
120
-                        }
121
-                        else
120
+                        } else
122 121
                         {
123 122
                             $os = OS::initEmpty();
124 123
                             $detectorResult->OS = $os;
@@ -129,8 +128,7 @@  discard block
 block discarded – undo
129 128
                         {
130 129
                             $device = new Device($result);
131 130
                             $detectorResult->Device = $device;
132
-                        }
133
-                        else
131
+                        } else
134 132
                         {
135 133
                             $device = Device::initEmpty();
136 134
                             $detectorResult->Device = $device;
@@ -142,8 +140,7 @@  discard block
 block discarded – undo
142 140
                             $browser = new Browser($result);
143 141
                             $browser->setVersion(self::getVersion($result, $ua));
144 142
                             $detectorResult->Browser = $browser;
145
-                        }
146
-                        else
143
+                        } else
147 144
                         {
148 145
                             $browser = Browser::initEmpty();
149 146
                             $detectorResult->Browser = $browser;
Please login to merge, or discard this patch.
tests/DeviceTest.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
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');
25
-        testUaListIsProperty($this,'isMobile',$ualist,true);
24
+        testUaList($this, 'Device', 'Name', $ualist, 'iPhone');
25
+        testUaListIsProperty($this, 'isMobile', $ualist, true);
26 26
     }
27 27
 
28 28
     public function testIPad()
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
             'Mozilla/5.0 (iPad; CPU OS 5_1_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Mobile/9B206'
35 35
         );
36 36
 
37
-        testUaList($this,'Device','Name',$ualist,'iPad');
37
+        testUaList($this, 'Device', 'Name', $ualist, 'iPad');
38 38
     }
39 39
 
40 40
     public function testLumia()
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0; NOKIA; Lumia 900)'
47 47
         );
48 48
 
49
-        testUaList($this,'Device','Name',$ualist,'Lumia');
50
-        testUaListIsProperty($this,'isMobile',$ualist,true);
49
+        testUaList($this, 'Device', 'Name', $ualist, 'Lumia');
50
+        testUaListIsProperty($this, 'isMobile', $ualist, true);
51 51
     }
52 52
 }
Please login to merge, or discard this patch.
tests/OsTest.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
             'Mozilla/1.1I (X11; I; UNIX_SV 4.2MP R4000)',
19 19
         );
20 20
 
21
-        testUaList($this,'OS','Name',$ualist,'Linux');
21
+        testUaList($this, 'OS', 'Name', $ualist, 'Linux');
22 22
     }
23 23
 
24 24
     public function testAIX()
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
             'Mozilla/4.04j2 [en] (X11; I; AIX 4.2) ',
28 28
         );
29 29
 
30
-        testUaList($this,'OS','Name',$ualist,'AIX');
30
+        testUaList($this, 'OS', 'Name', $ualist, 'AIX');
31 31
     }
32 32
 
33 33
     public function testAliyunOS()
@@ -36,6 +36,6 @@  discard block
 block discarded – undo
36 36
             'Mozilla/5.0 (Linux; U; AliyunOS 2.0; Android 4.0 Compatible; xx; R819T Build/AliyunOs-2012) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
37 37
         );
38 38
 
39
-        testUaList($this,'OS','Name',$ualist,'Aliyun OS');
39
+        testUaList($this, 'OS', 'Name', $ualist, 'Aliyun OS');
40 40
     }
41 41
 }
42 42
\ No newline at end of file
Please login to merge, or discard this patch.
tests/bootstrap.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
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,30 +28,30 @@  discard block
 block discarded – undo
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
 
41
-function testUaListBooleanTrue($object,$detectorProperty,$property,$uaList)
41
+function testUaListBooleanTrue($object, $detectorProperty, $property, $uaList)
42 42
 {
43
-    foreach($uaList as $ua)
43
+    foreach ($uaList as $ua)
44 44
     {
45 45
         $obj = Detector::analyse($ua)->$detectorProperty;
46 46
         $func = 'is'.$property;
47
-        $object->assertTrue($obj->$func(),'Object Property '.$property.' is no equal TRUE');
47
+        $object->assertTrue($obj->$func(), 'Object Property '.$property.' is no equal TRUE');
48 48
     }
49 49
 }
50 50
 
51
-function testUaListIsProperty($object,$detectorProperty,$uaList,$expectedValue)
51
+function testUaListIsProperty($object, $detectorProperty, $uaList, $expectedValue)
52 52
 {
53
-    foreach($uaList as $ua)
53
+    foreach ($uaList as $ua)
54 54
     {
55
-        $object->assertEquals($expectedValue,Detector::analyse($ua)->$detectorProperty);
55
+        $object->assertEquals($expectedValue, Detector::analyse($ua)->$detectorProperty);
56 56
     }
57 57
 }
58 58
\ No newline at end of file
Please login to merge, or discard this patch.
tests/RobotTest.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -22,8 +22,8 @@  discard block
 block discarded – undo
22 22
             'Tiny Tiny RSS/1.10 (http://tt-rss.org/)'
23 23
         );
24 24
 
25
-        testUaList($this,'Robot','Name',$ualist,'Tiny RSS');
26
-        testUaList($this,'Robot','Type',$ualist,'RSS Reader');
25
+        testUaList($this, 'Robot', 'Name', $ualist, 'Tiny RSS');
26
+        testUaList($this, 'Robot', 'Type', $ualist, 'RSS Reader');
27 27
     }
28 28
     /**
29 29
      * Test Google Bots
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
             'Mediapartners-Google'
44 44
         );
45 45
 
46
-        testUaList($this,'Robot','Owner',$ualist,'Google Inc.');
47
-        testUaList($this,'Robot','Type',$ualist,'Search Engine');
48
-        testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist);
46
+        testUaList($this, 'Robot', 'Owner', $ualist, 'Google Inc.');
47
+        testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine');
48
+        testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist);
49 49
     }
50 50
     /**
51 51
      * Test Yandex Bots
@@ -84,9 +84,9 @@  discard block
 block discarded – undo
84 84
             'Mozilla/5.0 (compatible; YandexSpravBot/1.0; +http://yandex.com/bots)'
85 85
         );
86 86
 
87
-        testUaList($this,'Robot','Owner',$ualist,'Yandex LLC.');
88
-        testUaList($this,'Robot','Type',$ualist,'Search Engine');
89
-        testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist);
87
+        testUaList($this, 'Robot', 'Owner', $ualist, 'Yandex LLC.');
88
+        testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine');
89
+        testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist);
90 90
     }
91 91
     /**
92 92
      * Test Bing Bots
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
             'Mozilla/5.0 (Windows Phone 8.1; ARM; Trident/7.0; Touch; rv:11.0; IEMobile/11.0; NOKIA; Lumia 530) like Gecko BingPreview/1.0b'
107 107
         );
108 108
 
109
-        testUaList($this,'Robot','Name',$ualist,'Bing');
110
-        testUaList($this,'Robot','Type',$ualist,'Search Engine');
111
-        testUaListBooleanTrue($this,'Robot','SearchEngine',$ualist);
109
+        testUaList($this, 'Robot', 'Name', $ualist, 'Bing');
110
+        testUaList($this, 'Robot', 'Type', $ualist, 'Search Engine');
111
+        testUaListBooleanTrue($this, 'Robot', 'SearchEngine', $ualist);
112 112
     }
113 113
 }
Please login to merge, or discard this patch.
src/Robot.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
                         }
Please login to merge, or discard this patch.
Braces   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -89,9 +89,9 @@
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
src/DetectorRule.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                 }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -126,8 +126,7 @@
 block discarded – undo
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
                         }
Please login to merge, or discard this patch.
src/Device.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.