Passed
Push — master ( a65292...b4400f )
by Alfred
03:40 queued 01:46
created
src/bin/GeoipNetwork.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -57,9 +57,11 @@
 block discarded – undo
57 57
         try
58 58
         {
59 59
             $this->validateAddress($ipAddress);
60
-            if (strpos($ipAddress, ':') !== false) // IPv6 address
60
+            if (strpos($ipAddress, ':') !== false) {
61
+                // IPv6 address
61 62
             {
62 63
                 $hex = unpack('H*hex', inet_pton($ipAddress));
64
+            }
63 65
                 $ipAddress = substr(preg_replace('/([A-f0-9]{4})/', "$1:", $hex['hex']), 0, -1);
64 66
                 $ipAddress = strtoupper($ipAddress);
65 67
             }
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@
 block discarded – undo
5 5
 {
6 6
     /**
7 7
      * @var string $ipAddress
8
-    **/
8
+     **/
9 9
     private $ipAddress=null;
10 10
     /**
11 11
      * Class constructor.
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -7,13 +7,13 @@  discard block
 block discarded – undo
7 7
     /**
8 8
      * @var string $ipAddress
9 9
     **/
10
-    private $ipAddress=null;
10
+    private $ipAddress = null;
11 11
     /**
12 12
      * Class constructor.
13 13
      *
14 14
      * @param string $ipAddress
15 15
      */
16
-    public function __construct(string $ipAddress=null)
16
+    public function __construct(string $ipAddress = null)
17 17
     {
18 18
         $ipAddress || $ipAddress = $this->getIPAddress();
19 19
         $this->validateAddress($ipAddress);
@@ -26,8 +26,8 @@  discard block
 block discarded – undo
26 26
     public function getIPAddress()
27 27
     {
28 28
         $ipAddress = '';
29
-        $ipKeys =['HTTP_X_COMING_FROM', 'HTTP_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_X_CLUSTER_CLIENT_IP',
30
-                'HTTP_X_FORWARDED', 'HTTP_VIA', 'HTTP_CLIENT_IP','HTTP_X_FORWARDED_FOR','REMOTE_ADDR'];
29
+        $ipKeys = ['HTTP_X_COMING_FROM', 'HTTP_FORWARDED', 'HTTP_FORWARDED_FOR', 'HTTP_X_CLUSTER_CLIENT_IP',
30
+                'HTTP_X_FORWARDED', 'HTTP_VIA', 'HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'REMOTE_ADDR'];
31 31
         foreach ($ipKeys as $key):
32 32
             if (array_key_exists($key, $_SERVER) && !empty($_SERVER[$key])):
33 33
                 $ipAddress = $_SERVER[$key];
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
                 break;
38 38
             endif;
39 39
         endforeach;
40
-        return $ipAddress?:'0.0.0.0';
40
+        return $ipAddress ?: '0.0.0.0';
41 41
     }
42 42
     /**
43 43
      * If IPV6, Returns the IP in it's fullest format.
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
     {
76 76
         $ipAddress = $this->expandAddress($ipAddress);
77 77
         if (strpos($ipAddress, ':') !== false):
78
-            $bin = inet_pton($ipAddress) ;
79
-            $ints = unpack('J2', $bin) ;
80
-            return $ints[1] ;
78
+            $bin = inet_pton($ipAddress);
79
+            $ints = unpack('J2', $bin);
80
+            return $ints[1];
81 81
         endif;
82 82
         return ip2long($ipAddress);
83 83
     }
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
         try
112 112
         {
113 113
             $ipAddress = $this->expandAddress($ipAddress);
114
-            if (strpos($ipAddress, ':') !== false) {return 6;}
114
+            if (strpos($ipAddress, ':') !== false) {return 6; }
115 115
             return 4;
116 116
         } catch (\UnexpectedValueException $th) {
117 117
             trigger_error($th->getMessage(), E_USER_ERROR);
Please login to merge, or discard this patch.
src/bin/GeoipDatabase.php 2 patches
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,9 +17,9 @@
 block discarded – undo
17 17
     private $oPDOInstance;
18 18
     /**
19 19
      * PDO transaction Counter
20
-    *
21
-    * @var integer
22
-    */
20
+     *
21
+     * @var integer
22
+     */
23 23
     private $transactionCounter = 0;
24 24
     /**
25 25
      * Class Constructor
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      */
78 78
     private function genDsn(string $database = null)
79 79
     {
80
-        $database || $database='Geoip.db.sqlite';
80
+        $database || $database = 'Geoip.db.sqlite';
81 81
         try {
82 82
             $destination = rtrim(dirname(__DIR__), self::DS);
83 83
             if (!is_writeable($destination)) {
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
                 throw new \Throwable($msg);
86 86
             }
87 87
             $info = new \SplFileInfo($database);
88
-            $dbName= $info->getFilename();
89
-            $dbSuffix='.sqlite';
90
-            if (substr_compare(strtolower($dbName), $dbSuffix, -strlen($dbSuffix)) !== 0) { $dbName .= $dbSuffix ; }
88
+            $dbName = $info->getFilename();
89
+            $dbSuffix = '.sqlite';
90
+            if (substr_compare(strtolower($dbName), $dbSuffix, -strlen($dbSuffix)) !== 0) { $dbName .= $dbSuffix; }
91 91
         } catch (\Throwable $th) {
92 92
             trigger_error($th->getMessage(), E_USER_ERROR);
93 93
         }
94 94
         $destination .= self::DS.'data';
95 95
         if (!is_dir($destination)) { mkdir($destination, '0755', true); }
96
-        return 'sqlite:'.realpath($destination).self::DS.$dbName ;
96
+        return 'sqlite:'.realpath($destination).self::DS.$dbName;
97 97
     }
98 98
     /**
99 99
      * Get the table list in the database
@@ -151,16 +151,16 @@  discard block
 block discarded – undo
151 151
             $sCommand .= 'FROM `ipv%dRange` ';
152 152
             $sCommand .= 'WHERE `start` <= :start ';
153 153
             $sCommand .= 'ORDER BY start DESC LIMIT 1';
154
-            $statement = $this->oPDOInstance->prepare(sprintf($sCommand, $ipVersion)) ;
155
-            $statement->execute([':start' => $start ]) ;
156
-            $row = $statement->fetch(\PDO::FETCH_OBJ) ;
154
+            $statement = $this->oPDOInstance->prepare(sprintf($sCommand, $ipVersion));
155
+            $statement->execute([':start' => $start]);
156
+            $row = $statement->fetch(\PDO::FETCH_OBJ);
157 157
             if (is_bool($row) && $row === false)
158 158
             {
159 159
                 $row = new \stdClass();
160
-                $row->end = 0 ;
160
+                $row->end = 0;
161 161
             }
162
-            if ($row->end < $start || !$row->country) { $row->country = 'ZZ' ; }
163
-            return $row->country ;
162
+            if ($row->end < $start || !$row->country) { $row->country = 'ZZ'; }
163
+            return $row->country;
164 164
         } catch (\PDOException $th) {
165 165
             trigger_error($th->getMessage(), E_USER_ERROR);
166 166
         }
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
      * @param array $tablesList
172 172
      * @return void
173 173
      */
174
-    public function flush(array $tablesList=[])
174
+    public function flush(array $tablesList = [])
175 175
     {
176 176
         !empty($tablesList) || $tablesList = $this->showTables();
177 177
         is_array($tablesList) || $tablesList = [$tablesList];
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
                 $this->oPDOInstance->query('VACUUM');
186 186
             endif;
187 187
         } catch (\PDOException $th) {
188
-            trigger_error('Statement failed: ' . $th->getMessage(), E_USER_ERROR);
188
+            trigger_error('Statement failed: '.$th->getMessage(), E_USER_ERROR);
189 189
         }
190 190
     }
191 191
     /**
@@ -201,16 +201,16 @@  discard block
 block discarded – undo
201 201
     {
202 202
         try
203 203
         {
204
-            $sQuery ='INSERT INTO `ipv%dRange` (`start`, `end`, `country`) values (:start, :end, :country)';
204
+            $sQuery = 'INSERT INTO `ipv%dRange` (`start`, `end`, `country`) values (:start, :end, :country)';
205 205
             $command = sprintf($sQuery, $ipVersion);
206 206
             $statement = $this->oPDOInstance->prepare($command);
207 207
             $statement->execute([
208 208
                 ':start'   => $start,
209 209
                 ':end'     => $end,
210 210
                 ':country' => $country
211
-            ]) ;
211
+            ]);
212 212
         } catch (\PDOException $th) {
213
-            trigger_error('Statement failed: ' . $th->getMessage(), E_USER_ERROR);
213
+            trigger_error('Statement failed: '.$th->getMessage(), E_USER_ERROR);
214 214
         }
215 215
     }
216 216
     /**
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
      */
221 221
     public function beginTransaction()
222 222
     {
223
-        if (!$this->transactionCounter++) {return $this->oPDOInstance->beginTransaction();}
223
+        if (!$this->transactionCounter++) {return $this->oPDOInstance->beginTransaction(); }
224 224
         return $this->transactionCounter >= 0;
225 225
     }
226 226
     /**
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     public function commit()
232 232
     {
233
-        if (!--$this->transactionCounter) {return $this->oPDOInstance->commit();}
233
+        if (!--$this->transactionCounter) {return $this->oPDOInstance->commit(); }
234 234
         return $this->transactionCounter >= 0;
235 235
     }
236 236
     /**
Please login to merge, or discard this patch.
src/GeoIP2Country.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,13 +10,13 @@
 block discarded – undo
10 10
      * PDO SQLite3 database instance
11 11
      *
12 12
      * @var GeoipDatabase
13
-    **/
13
+     **/
14 14
     private $oDBInstance=null;
15 15
     /**
16 16
      * Network tools class instance
17 17
      *
18 18
      * @var GeoipNetwork
19
-    **/
19
+     **/
20 20
     private $oNetwork=null;
21 21
     /**
22 22
      * Class Constructor
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@  discard block
 block discarded – undo
11 11
      *
12 12
      * @var GeoipDatabase
13 13
     **/
14
-    private $oDBInstance=null;
14
+    private $oDBInstance = null;
15 15
     /**
16 16
      * Network tools class instance
17 17
      *
18 18
      * @var GeoipNetwork
19 19
     **/
20
-    private $oNetwork=null;
20
+    private $oNetwork = null;
21 21
     /**
22 22
      * Class Constructor
23 23
      *
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
      * @param string|null $ipAddress
36 36
      * @return string
37 37
      */
38
-    public function resolve(string $ipAddress= null): string
38
+    public function resolve(string $ipAddress = null): string
39 39
     {
40 40
         $ipAddress || $ipAddress = $this->oNetwork->getIPAddress();
41 41
         $ipVersion = $this->oNetwork->ipVersion($ipAddress);
@@ -46,10 +46,10 @@  discard block
 block discarded – undo
46 46
      * @param mixed|null $ipAddress
47 47
      * @return bool
48 48
      */
49
-    public function isReservedAddress($ipAddress=null): bool
49
+    public function isReservedAddress($ipAddress = null): bool
50 50
     {
51 51
         $ipAddress || $ipAddress = $this->oNetwork->getIPAddress();
52 52
         $countryCode = $this->resolve($ipAddress);
53
-        return !$countryCode || strcasecmp($countryCode, 'ZZ') == 0 ;
53
+        return !$countryCode || strcasecmp($countryCode, 'ZZ') == 0;
54 54
     }
55 55
 }
Please login to merge, or discard this patch.