@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | * @access protected |
| 44 | 44 | * @var array |
| 45 | 45 | */ |
| 46 | - protected $selfIps = []; |
|
| 46 | + protected $selfIps = [ ]; |
|
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | 49 | * The maximum number of milliseconds to allow cURL functions to execute. If libcurl is |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * to execute. Default is 0, no timeout |
| 66 | 66 | * |
| 67 | 67 | */ |
| 68 | - public function __construct(string $apiKey, array $myIps = [], int $timeout = 0) |
|
| 68 | + public function __construct(string $apiKey, array $myIps = [ ], int $timeout = 0) |
|
| 69 | 69 | { |
| 70 | 70 | $this->aipdbApiKey = $apiKey; |
| 71 | 71 | $this->selfIps = $myIps; |
@@ -111,17 +111,17 @@ discard block |
||
| 111 | 111 | public function report(string $ip, string $categories, string $message): ApiResponse |
| 112 | 112 | { |
| 113 | 113 | // ip must be set |
| 114 | - if (empty($ip)){ |
|
| 114 | + if (empty($ip)) { |
|
| 115 | 115 | throw new \InvalidArgumentException('Ip was empty'); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | // categories must be set |
| 119 | - if (empty($categories)){ |
|
| 119 | + if (empty($categories)) { |
|
| 120 | 120 | throw new \InvalidArgumentException('Categories list was empty'); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // message must be set |
| 124 | - if (empty($message)){ |
|
| 124 | + if (empty($message)) { |
|
| 125 | 125 | throw new \InvalidArgumentException('Report message was empty'); |
| 126 | 126 | } |
| 127 | 127 | |
@@ -178,16 +178,16 @@ discard block |
||
| 178 | 178 | public function bulkReport(string $filePath): ApiResponse |
| 179 | 179 | { |
| 180 | 180 | // check file exists |
| 181 | - if (!file_exists($filePath) || !is_file($filePath)){ |
|
| 181 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 182 | 182 | throw new \InvalidArgumentException('The file [' . $filePath . '] does not exist.'); |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | // check file is readable |
| 186 | - if (!is_readable($filePath)){ |
|
| 186 | + if (!is_readable($filePath)) { |
|
| 187 | 187 | throw new InvalidPermissionException('The file [' . $filePath . '] is not readable.'); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - return $this->apiRequest('bulk-report', [], 'POST', $filePath); |
|
| 190 | + return $this->apiRequest('bulk-report', [ ], 'POST', $filePath); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | public function clearAddress(string $ip): ApiResponse |
| 212 | 212 | { |
| 213 | 213 | // ip must be set |
| 214 | - if (empty($ip)){ |
|
| 214 | + if (empty($ip)) { |
|
| 215 | 215 | throw new \InvalidArgumentException('IP argument must be set.'); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | - return $this->apiRequest('clear-address', ['ipAddress' => $ip ], "DELETE") ; |
|
| 218 | + return $this->apiRequest('clear-address', [ 'ipAddress' => $ip ], "DELETE"); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -233,12 +233,12 @@ discard block |
||
| 233 | 233 | public function check(string $ip, int $maxAgeInDays = 30, bool $verbose = false): ApiResponse |
| 234 | 234 | { |
| 235 | 235 | // max age must be less or equal to 365 |
| 236 | - if ( $maxAgeInDays > 365 || $maxAgeInDays < 1 ){ |
|
| 236 | + if ($maxAgeInDays > 365 || $maxAgeInDays < 1) { |
|
| 237 | 237 | throw new \InvalidArgumentException('maxAgeInDays must be between 1 and 365.'); |
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | // ip must be set |
| 241 | - if (empty($ip)){ |
|
| 241 | + if (empty($ip)) { |
|
| 242 | 242 | throw new \InvalidArgumentException('ip argument must be set (empty value given)'); |
| 243 | 243 | } |
| 244 | 244 | |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | ]; |
| 250 | 250 | |
| 251 | 251 | // option |
| 252 | - if ($verbose){ |
|
| 253 | - $data['verbose'] = true; |
|
| 252 | + if ($verbose) { |
|
| 253 | + $data[ 'verbose' ] = true; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - return $this->apiRequest('check', $data, 'GET') ; |
|
| 256 | + return $this->apiRequest('check', $data, 'GET'); |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | public function checkBlock(string $network, int $maxAgeInDays = 30): ApiResponse |
| 303 | 303 | { |
| 304 | 304 | // max age must be between 1 and 365 |
| 305 | - if ($maxAgeInDays > 365 || $maxAgeInDays < 1){ |
|
| 305 | + if ($maxAgeInDays > 365 || $maxAgeInDays < 1) { |
|
| 306 | 306 | throw new \InvalidArgumentException('maxAgeInDays must be between 1 and 365 (' . $maxAgeInDays . ' was given)'); |
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | // ip must be set |
| 310 | - if (empty($network)){ |
|
| 310 | + if (empty($network)) { |
|
| 311 | 311 | throw new \InvalidArgumentException('network argument must be set (empty value given)'); |
| 312 | 312 | } |
| 313 | 313 | |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | */ |
| 337 | 337 | public function blacklist(int $limit = 10000, bool $plainText = false, int $confidenceMinimum = 100): ApiResponse |
| 338 | 338 | { |
| 339 | - if ($limit < 1){ |
|
| 339 | + if ($limit < 1) { |
|
| 340 | 340 | throw new \InvalidArgumentException('limit must be at least 1 (' . $limit . ' was given)'); |
| 341 | 341 | } |
| 342 | 342 | |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | |
| 349 | 349 | // plaintext paremeter has no value and must be added only when true |
| 350 | 350 | // (set plaintext=false won't work) |
| 351 | - if ($plainText){ |
|
| 352 | - $data['plaintext'] = $plainText; |
|
| 351 | + if ($plainText) { |
|
| 352 | + $data[ 'plaintext' ] = $plainText; |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | return $this->apiRequest('blacklist', $data, 'GET'); |
@@ -370,9 +370,9 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | protected function apiRequest(string $path, array $data, string $method = 'GET', string $csvFilePath = ''): ApiResponse |
| 372 | 372 | { |
| 373 | - $curlErrorNumber = -1; // will be used later to check curl execution |
|
| 373 | + $curlErrorNumber = -1; // will be used later to check curl execution |
|
| 374 | 374 | $curlErrorMessage = ''; |
| 375 | - $url = $this->aipdbApiEndpoint . $path; // api url |
|
| 375 | + $url = $this->aipdbApiEndpoint . $path; // api url |
|
| 376 | 376 | |
| 377 | 377 | // set the wanted format, JSON (required to prevent having full html page on error) |
| 378 | 378 | // and the AbuseIPDB API Key as a header |
@@ -385,8 +385,8 @@ discard block |
||
| 385 | 385 | $ch = curl_init(); |
| 386 | 386 | |
| 387 | 387 | // for csv |
| 388 | - if (!empty($csvFilePath)){ |
|
| 389 | - $cfile = new \CurlFile($csvFilePath, 'text/csv', 'csv'); |
|
| 388 | + if (!empty($csvFilePath)) { |
|
| 389 | + $cfile = new \CurlFile($csvFilePath, 'text/csv', 'csv'); |
|
| 390 | 390 | //curl file itself return the realpath with prefix of @ |
| 391 | 391 | $data = array('csv' => $cfile); |
| 392 | 392 | } |
@@ -426,7 +426,7 @@ discard block |
||
| 426 | 426 | // close connection |
| 427 | 427 | curl_close($ch); |
| 428 | 428 | |
| 429 | - if ($curlErrorNumber !== 0){ |
|
| 429 | + if ($curlErrorNumber !== 0) { |
|
| 430 | 430 | throw new \RuntimeException($curlErrorMessage); |
| 431 | 431 | } |
| 432 | 432 | |
@@ -449,7 +449,7 @@ discard block |
||
| 449 | 449 | $message = str_replace('\\', '', $message); |
| 450 | 450 | |
| 451 | 451 | // Remove self ips |
| 452 | - foreach ($this->selfIps as $ip){ |
|
| 452 | + foreach ($this->selfIps as $ip) { |
|
| 453 | 453 | $message = str_replace($ip, '*', $message); |
| 454 | 454 | } |
| 455 | 455 | |