Completed
Push — 3.0.0 ( f036f7...109b16 )
by Serhii
04:36
created
src/Detector.php 1 patch
Spacing   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -21,14 +21,14 @@  discard block
 block discarded – undo
21 21
     private static function initialize($pathToData = 'auto')
22 22
     {
23 23
         if ($pathToData == 'auto') {
24
-            $pathToData = str_replace('src', 'data', __DIR__) . '/';
24
+            $pathToData = str_replace('src', 'data', __DIR__).'/';
25 25
         }
26 26
 
27 27
         if (self::$_xmlData === null) {
28 28
             $xml = array('Robot', 'Browser', 'Device', 'OS');
29 29
             $xmlData = array();
30 30
             foreach ($xml as $name) {
31
-                $xmlData[$name] = simplexml_load_file($pathToData . strtolower($name) . '.xml');
31
+                $xmlData[$name] = simplexml_load_file($pathToData.strtolower($name).'.xml');
32 32
             }
33 33
             self::$_xmlData = $xmlData;
34 34
             self::$isInitialized = true;
@@ -40,20 +40,20 @@  discard block
 block discarded – undo
40 40
             $fields = array('OS');
41 41
             self::$_ymlData = [];
42 42
             foreach ($fields as $name) {
43
-                self::$_ymlData[$name] = $parser->parse(file_get_contents($pathToData . strtolower($name) . '.yml'));
43
+                self::$_ymlData[$name] = $parser->parse(file_get_contents($pathToData.strtolower($name).'.yml'));
44 44
             }
45 45
         }
46 46
     }
47 47
 
48
-    public static function analyse($uaString='UA')
48
+    public static function analyse($uaString = 'UA')
49 49
     {
50 50
         $ua = $uaString;
51
-        if($uaString == 'UA')
51
+        if ($uaString == 'UA')
52 52
         {
53 53
             $ua = $_SERVER['HTTP_USER_AGENT'];
54 54
         }
55 55
 
56
-        if(!self::$isInitialized)
56
+        if (!self::$isInitialized)
57 57
             self::initialize();
58 58
         $xml = self::$_xmlData;
59 59
 
@@ -61,20 +61,20 @@  discard block
 block discarded – undo
61 61
         $detectorResult->uaString = $ua;
62 62
         $ns = '\\EndorphinStudio\\Detector\\';
63 63
 
64
-        foreach($xml as $key => $item)
64
+        foreach ($xml as $key => $item)
65 65
         {
66
-            $data = self::analysePart($xml,$key,$ua);
66
+            $data = self::analysePart($xml, $key, $ua);
67 67
             $classname = $ns.$key;
68
-            if($data !== null)
68
+            if ($data !== null)
69 69
             {
70 70
                 $object = new $classname($data);
71
-                if($key == 'OS' || $key == 'Browser')
71
+                if ($key == 'OS' || $key == 'Browser')
72 72
                 {
73 73
                     $object->setVersion(self::getVersion($data, $ua));
74 74
                 }
75
-                if($key == 'Robot')
75
+                if ($key == 'Robot')
76 76
                 {
77
-                    if($object->getName() != D_NA)
77
+                    if ($object->getName() != D_NA)
78 78
                     {
79 79
                         $detectorResult->isBot = true;
80 80
                     }
@@ -99,13 +99,13 @@  discard block
 block discarded – undo
99 99
      * @param string $uaString User agent
100 100
      * @return \SimpleXMLElement xml element
101 101
      */
102
-    private static function analysePart($xmlData,$key,$uaString)
102
+    private static function analysePart($xmlData, $key, $uaString)
103 103
     {
104 104
         $data = $xmlData[$key]->data;
105
-        foreach($data as $xmlItem)
105
+        foreach ($data as $xmlItem)
106 106
         {
107 107
             $pattern = '/'.$xmlItem->pattern.'/';
108
-            if(preg_match($pattern,$uaString))
108
+            if (preg_match($pattern, $uaString))
109 109
             {
110 110
                 return $xmlItem;
111 111
             }
@@ -118,21 +118,21 @@  discard block
 block discarded – undo
118 118
      * @param string $uaString User agent
119 119
      * @return string Version
120 120
      */
121
-    private static function getVersion(\SimpleXMLElement $xmlItem,$uaString)
121
+    private static function getVersion(\SimpleXMLElement $xmlItem, $uaString)
122 122
     {
123
-        if($xmlItem !== null)
123
+        if ($xmlItem !== null)
124 124
         {
125
-            foreach($xmlItem->children() as $node)
125
+            foreach ($xmlItem->children() as $node)
126 126
             {
127
-                if($node->getName() == 'versionPattern')
127
+                if ($node->getName() == 'versionPattern')
128 128
                 {
129 129
                     $vPattern = $node->__toString();
130
-                    $version = '/' . $vPattern . '(\/| )[\w-._]{1,15}/';
130
+                    $version = '/'.$vPattern.'(\/| )[\w-._]{1,15}/';
131 131
                     $uaString = str_replace(' NT', '', $uaString);
132 132
                     if (preg_match($version, $uaString)) {
133 133
                         preg_match($version, $uaString, $v);
134 134
                         $version = $v[0];
135
-                        $version = preg_replace('/' . $vPattern . '/', '', $version);
135
+                        $version = preg_replace('/'.$vPattern.'/', '', $version);
136 136
                         $version = str_replace(';', '', $version);
137 137
                         $version = str_replace(' ', '', $version);
138 138
                         $version = str_replace('/', '', $version);
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
             '10.0' => '10'
175 175
         );
176 176
 
177
-        if(array_key_exists(strval($version),$versions))
177
+        if (array_key_exists(strval($version), $versions))
178 178
             return $versions[strval($version)];
179 179
         else
180 180
             return D_NA;
@@ -187,14 +187,14 @@  discard block
 block discarded – undo
187 187
     private static function checkRules(DetectorResult $result)
188 188
     {
189 189
         $Rules = DetectorRule::loadRulesFromFile();
190
-        foreach($Rules as $rule)
190
+        foreach ($Rules as $rule)
191 191
         {
192 192
             $objectType = $rule->getObjectType();
193 193
             $objectProperty = $rule->getObjectProperty();
194 194
             $targetType = $rule->getTargetType();
195 195
             $targetValue = $rule->isTargetValue();
196 196
             $func = 'get'.$objectProperty;
197
-            if($result->$objectType !== null)
197
+            if ($result->$objectType !== null)
198 198
             {
199 199
                 if ($result->$objectType->$func() == $rule->getObjectPropertyValue()) {
200 200
                     $result->$targetType = $targetValue;
@@ -208,16 +208,16 @@  discard block
 block discarded – undo
208 208
     private static function checkModelName(DetectorResult $result)
209 209
     {
210 210
         $models = DeviceModel::loadFromFile();
211
-        foreach($models as $model)
211
+        foreach ($models as $model)
212 212
         {
213
-            if($model->getDeviceName() === $result->Device->getName())
213
+            if ($model->getDeviceName() === $result->Device->getName())
214 214
             {
215 215
                 $pattern = '/'.$model->getPattern().'/';
216
-                preg_match($pattern,$result->uaString,$match);
216
+                preg_match($pattern, $result->uaString, $match);
217 217
                 $result->Device->setModelName($match[1]);
218 218
             }
219 219
         }
220 220
         return $result;
221 221
     }
222 222
 }
223
-define('D_NA','N\A');
223
+define('D_NA', 'N\A');
Please login to merge, or discard this patch.