Completed
Push — 3.0.0 ( e168bd...cd1823 )
by Serhii
02:34
created
src/DeviceModel.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
     public function __construct(\SimpleXMLElement $xmlData)
70 70
     {
71
-        if($xmlData !== null)
71
+        if ($xmlData !== null)
72 72
         {
73 73
             foreach ($xmlData->children() as $child)
74 74
             {
@@ -84,10 +84,10 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public static function loadFromFile()
86 86
     {
87
-        $path = str_replace('src','data',__DIR__).'/deviceModels.xml';
87
+        $path = str_replace('src', 'data', __DIR__).'/deviceModels.xml';
88 88
         $models = array();
89 89
         $xmlObj = simplexml_load_file($path);
90
-        foreach($xmlObj->children() as $rule)
90
+        foreach ($xmlObj->children() as $rule)
91 91
         {
92 92
             $models[] = new self($rule);
93 93
         }
Please login to merge, or discard this patch.
src/Detector.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
                     }
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
      * @param string $uaString User agent
86 86
      * @return \SimpleXMLElement xml element
87 87
      */
88
-    private static function analysePart($xmlData,$key,$uaString)
88
+    private static function analysePart($xmlData, $key, $uaString)
89 89
     {
90 90
         $data = $xmlData[$key]->data;
91
-        foreach($data as $xmlItem)
91
+        foreach ($data as $xmlItem)
92 92
         {
93 93
             $pattern = '/'.$xmlItem->pattern.'/';
94
-            if(preg_match($pattern,$uaString))
94
+            if (preg_match($pattern, $uaString))
95 95
             {
96 96
                 return $xmlItem;
97 97
             }
@@ -104,21 +104,21 @@  discard block
 block discarded – undo
104 104
      * @param string $uaString User agent
105 105
      * @return string Version
106 106
      */
107
-    private static function getVersion(\SimpleXMLElement $xmlItem,$uaString)
107
+    private static function getVersion(\SimpleXMLElement $xmlItem, $uaString)
108 108
     {
109
-        if($xmlItem !== null)
109
+        if ($xmlItem !== null)
110 110
         {
111
-            foreach($xmlItem->children() as $node)
111
+            foreach ($xmlItem->children() as $node)
112 112
             {
113
-                if($node->getName() == 'versionPattern')
113
+                if ($node->getName() == 'versionPattern')
114 114
                 {
115 115
                     $vPattern = $node->__toString();
116
-                    $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/';
116
+                    $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/';
117 117
                     $uaString = str_replace(' NT', '', $uaString);
118 118
                     if (preg_match($version, $uaString)) {
119 119
                         preg_match($version, $uaString, $v);
120 120
                         $version = $v[0];
121
-                        $version = preg_replace('/' . $vPattern . '/', '', $version);
121
+                        $version = preg_replace('/'.$vPattern.'/', '', $version);
122 122
                         $version = str_replace(';', '', $version);
123 123
                         $version = str_replace(' ', '', $version);
124 124
                         $version = str_replace('/', '', $version);
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             '10.0' => '10'
161 161
         );
162 162
 
163
-        if(array_key_exists(strval($version),$versions))
163
+        if (array_key_exists(strval($version), $versions))
164 164
             return $versions[strval($version)];
165 165
         else
166 166
             return D_NA;
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
     private static function checkRules(DetectorResult $result)
174 174
     {
175 175
         $Rules = DetectorRule::loadRulesFromFile();
176
-        foreach($Rules as $rule)
176
+        foreach ($Rules as $rule)
177 177
         {
178 178
             $objectType = $rule->getObjectType();
179 179
             $objectProperty = $rule->getObjectProperty();
180 180
             $targetType = $rule->getTargetType();
181 181
             $targetValue = $rule->isTargetValue();
182 182
             $func = 'get'.$objectProperty;
183
-            if($result->$objectType !== null)
183
+            if ($result->$objectType !== null)
184 184
             {
185 185
                 if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) {
186 186
                     $result->$targetType = $targetValue;
@@ -194,16 +194,16 @@  discard block
 block discarded – undo
194 194
     private static function checkModelName(DetectorResult $result)
195 195
     {
196 196
         $models = DeviceModel::loadFromFile();
197
-        foreach($models as $model)
197
+        foreach ($models as $model)
198 198
         {
199
-            if($model->getDeviceName() === $result->Device->getName())
199
+            if ($model->getDeviceName() === $result->Device->getName())
200 200
             {
201 201
                 $pattern = '/'.$model->getPattern().'/';
202
-                preg_match($pattern,$result->uaString,$match);
202
+                preg_match($pattern, $result->uaString, $match);
203 203
                 $result->Device->setModelName($match[1]);
204 204
             }
205 205
         }
206 206
         return $result;
207 207
     }
208 208
 }
209
-define('D_NA','N\A');
209
+define('D_NA', 'N\A');
Please login to merge, or discard this patch.