Passed
Pull Request — master (#24)
by Alfred
02:18
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 = null;
29
-        $serverIPKeys =['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
+        $serverIPKeys = ['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 ($serverIPKeys as $IPKey):
32 32
             if (array_key_exists($IPKey, $_SERVER)) {
33 33
                 if (!strlen($_SERVER[$IPKey])) { continue; }
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
         {
40 40
             $ipAddress = substr($ipAddress, 0, ($commaPos - 1));
41 41
         }
42
-        return $ipAddress?:'0.0.0.0';
42
+        return $ipAddress ?: '0.0.0.0';
43 43
     }
44 44
     /**
45 45
      * If IPV6, Returns the IP in it's fullest format.
@@ -77,9 +77,9 @@  discard block
 block discarded – undo
77 77
     {
78 78
         $ipAddress = $this->expandAddress($ipAddress);
79 79
         if (strpos($ipAddress, ':') !== false):
80
-            $bin = inet_pton($ipAddress) ;
81
-            $ints = unpack('J2', $bin) ;
82
-            return $ints[1] ;
80
+            $bin = inet_pton($ipAddress);
81
+            $ints = unpack('J2', $bin);
82
+            return $ints[1];
83 83
         endif;
84 84
         return ip2long($ipAddress);
85 85
     }
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         try
114 114
         {
115 115
             $ipAddress = $this->expandAddress($ipAddress);
116
-            if (strpos($ipAddress, ':') !== false) {return 6;}
116
+            if (strpos($ipAddress, ':') !== false) {return 6; }
117 117
             return 4;
118 118
         } catch (\Throwable $th) {
119 119
             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
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
      */
81 81
     private function genDsn(string $database = null)
82 82
     {
83
-        $database || $database='Geoip.db.sqlite';
83
+        $database || $database = 'Geoip.db.sqlite';
84 84
         try {
85 85
             $destination = rtrim(dirname(__DIR__), self::DS);
86 86
             if (!is_writeable($destination))
@@ -88,15 +88,15 @@  discard block
 block discarded – undo
88 88
                 throw new \Throwable(sprintf('The required destination path is not writable: `%s`', $destination));
89 89
             }
90 90
             $info = new \SplFileInfo($database);
91
-            $dbName= $info->getFilename();
92
-            $dbSuffix='.sqlite';
93
-            if (substr_compare(strtolower($dbName), $dbSuffix, -strlen($dbSuffix)) !== 0) { $dbName .= $dbSuffix ; }
91
+            $dbName = $info->getFilename();
92
+            $dbSuffix = '.sqlite';
93
+            if (substr_compare(strtolower($dbName), $dbSuffix, -strlen($dbSuffix)) !== 0) { $dbName .= $dbSuffix; }
94 94
         } catch (\Throwable $th) {
95 95
             trigger_error($th->getMessage(), E_USER_ERROR);
96 96
         }
97 97
         $destination .= self::DS.'data';
98 98
         if (!is_dir($destination)) { mkdir($destination, '0755', true); }
99
-        return 'sqlite:'.realpath($destination).self::DS.$dbName ;
99
+        return 'sqlite:'.realpath($destination).self::DS.$dbName;
100 100
     }
101 101
     /**
102 102
      * Get the table list in the database
@@ -154,16 +154,16 @@  discard block
 block discarded – undo
154 154
             $sCommand .= 'FROM `ipv%dRange` ';
155 155
             $sCommand .= 'WHERE `start` <= :start ';
156 156
             $sCommand .= 'ORDER BY start DESC LIMIT 1';
157
-            $statement = $this->oPDOInstance->prepare(sprintf($sCommand, $ipVersion)) ;
158
-            $statement->execute([':start' => $start ]) ;
159
-            $row = $statement->fetch(\PDO::FETCH_OBJ) ;
157
+            $statement = $this->oPDOInstance->prepare(sprintf($sCommand, $ipVersion));
158
+            $statement->execute([':start' => $start]);
159
+            $row = $statement->fetch(\PDO::FETCH_OBJ);
160 160
             if (is_bool($row) && $row === false)
161 161
             {
162 162
                 $row = new \stdClass();
163
-                $row->end = 0 ;
163
+                $row->end = 0;
164 164
             }
165
-            if ($row->end < $start || !$row->country) { $row->country = 'ZZ' ; }
166
-            return $row->country ;
165
+            if ($row->end < $start || !$row->country) { $row->country = 'ZZ'; }
166
+            return $row->country;
167 167
         } catch (\PDOException $th) {
168 168
             trigger_error($th->getMessage(), E_USER_ERROR);
169 169
         }
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * @param array $tablesList
175 175
      * @return void
176 176
      */
177
-    public function flush(array $tablesList=[])
177
+    public function flush(array $tablesList = [])
178 178
     {
179 179
         !empty($tablesList) || $tablesList = $this->showTables();
180 180
         is_array($tablesList) || $tablesList = [$tablesList];
@@ -188,7 +188,7 @@  discard block
 block discarded – undo
188 188
                 $this->oPDOInstance->query('VACUUM');
189 189
             endif;
190 190
         } catch (\PDOException $th) {
191
-            trigger_error('Statement failed: ' . $th->getMessage(), E_USER_ERROR);
191
+            trigger_error('Statement failed: '.$th->getMessage(), E_USER_ERROR);
192 192
         }
193 193
     }
194 194
     /**
@@ -204,17 +204,17 @@  discard block
 block discarded – undo
204 204
     {
205 205
         try
206 206
         {
207
-            $sQuery ='INSERT INTO `ipv%dRange` (`start`, `end`, `country`) values (:start, :end, :country)';
207
+            $sQuery = 'INSERT INTO `ipv%dRange` (`start`, `end`, `country`) values (:start, :end, :country)';
208 208
             $command = sprintf($sQuery, $ipVersion);
209 209
             $statement = $this->oPDOInstance->prepare($command);
210 210
             $statement->execute([
211 211
                 ':start'   => $start,
212 212
                 ':end'     => $end,
213 213
                 ':country' => $country
214
-            ]) ;
214
+            ]);
215 215
             return $this->oPDOInstance->lastInsertId();
216 216
         } catch (\PDOException $th) {
217
-            trigger_error('Statement failed: ' . $th->getMessage(), E_USER_ERROR);
217
+            trigger_error('Statement failed: '.$th->getMessage(), E_USER_ERROR);
218 218
         }
219 219
     }
220 220
     /**
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      */
225 225
     public function beginTransaction()
226 226
     {
227
-        if (!$this->transactionCounter++) {return $this->oPDOInstance->beginTransaction();}
227
+        if (!$this->transactionCounter++) {return $this->oPDOInstance->beginTransaction(); }
228 228
         return $this->transactionCounter >= 0;
229 229
     }
230 230
     /**
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
      */
235 235
     public function commit()
236 236
     {
237
-        if (!--$this->transactionCounter) {return $this->oPDOInstance->commit();}
237
+        if (!--$this->transactionCounter) {return $this->oPDOInstance->commit(); }
238 238
         return $this->transactionCounter >= 0;
239 239
     }
240 240
     /**
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.