@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false) |
| 147 | 147 | { |
| 148 | - // ip must be set |
|
| 148 | + // ip must be set |
|
| 149 | 149 | if (empty($ip)){ |
| 150 | 150 | throw new \InvalidArgumentException('Ip was empty'); |
| 151 | 151 | } |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // message must be set |
| 159 | - if (empty($message)){ |
|
| 159 | + if (empty($message)){ |
|
| 160 | 160 | throw new \InvalidArgumentException('report message was empty'); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | // option |
| 313 | 313 | if ($verbose){ |
| 314 | - $data['verbose'] = true; |
|
| 314 | + $data['verbose'] = true; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $response = $this->apiRequest('check', $data, 'GET', $returnArray) ; |
@@ -457,14 +457,14 @@ discard block |
||
| 457 | 457 | 'Key: ' . $this->aipdbApiKey, |
| 458 | 458 | ]); |
| 459 | 459 | |
| 460 | - // execute curl call |
|
| 461 | - $result = curl_exec($ch); |
|
| 460 | + // execute curl call |
|
| 461 | + $result = curl_exec($ch); |
|
| 462 | 462 | |
| 463 | - // close connection |
|
| 464 | - curl_close($ch); |
|
| 463 | + // close connection |
|
| 464 | + curl_close($ch); |
|
| 465 | 465 | |
| 466 | - // return response as JSON data |
|
| 467 | - return $result; |
|
| 466 | + // return response as JSON data |
|
| 467 | + return $result; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /** |
@@ -475,7 +475,7 @@ discard block |
||
| 475 | 475 | * @access public |
| 476 | 476 | * @param string $message The original message |
| 477 | 477 | * |
| 478 | - * @return string |
|
| 478 | + * @return string |
|
| 479 | 479 | */ |
| 480 | 480 | protected function cleanMessage(string $message) |
| 481 | 481 | { |
@@ -500,10 +500,10 @@ discard block |
||
| 500 | 500 | * |
| 501 | 501 | * @access public |
| 502 | 502 | * @static |
| 503 | - * @param string $filePath The file's full path |
|
| 504 | - * @param bool $throwError Throw error on true or silent process. Default is true |
|
| 503 | + * @param string $filePath The file's full path |
|
| 504 | + * @param bool $throwError Throw error on true or silent process. Default is true |
|
| 505 | 505 | * |
| 506 | - * @return object|null |
|
| 506 | + * @return object|null |
|
| 507 | 507 | * @throws \Exception |
| 508 | 508 | * @throws \LogicException |
| 509 | 509 | */ |
@@ -511,10 +511,10 @@ discard block |
||
| 511 | 511 | { |
| 512 | 512 | // check file exists |
| 513 | 513 | if (!file_exists($filePath) || !is_file($filePath)){ |
| 514 | - if ($throwError) { |
|
| 514 | + if ($throwError) { |
|
| 515 | 515 | throw new \Exception('Config file not found'); |
| 516 | - } |
|
| 517 | - return null; |
|
| 516 | + } |
|
| 517 | + return null; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | // get and parse content |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | * @access protected |
| 51 | 51 | * @var array $selfIps |
| 52 | 52 | */ |
| 53 | - protected $selfIps = []; |
|
| 53 | + protected $selfIps = [ ]; |
|
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | 56 | * Constructor |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @param array $myIps The Ips/domain name you dont want to display in report messages |
| 62 | 62 | * |
| 63 | 63 | */ |
| 64 | - public function __construct(string $apiKey, string $userId, array $myIps = []) |
|
| 64 | + public function __construct(string $apiKey, string $userId, array $myIps = [ ]) |
|
| 65 | 65 | { |
| 66 | 66 | $this->aipdbApiKey = $apiKey; |
| 67 | 67 | $this->aipdbUserId = $userId; |
@@ -100,21 +100,21 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | |
| 102 | 102 | // check file exists |
| 103 | - if (!file_exists($configPath) || !is_file($configPath)){ |
|
| 103 | + if (!file_exists($configPath) || !is_file($configPath)) { |
|
| 104 | 104 | throw new \InvalidArgumentException('The file [' . $configPath . '] does not exist.'); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // check file is readable |
| 108 | - if (!is_readable($configPath)){ |
|
| 108 | + if (!is_readable($configPath)) { |
|
| 109 | 109 | throw new InvalidPermissionException('The file [' . $configPath . '] is not readable.'); |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | $keyConfig = self::loadJsonFile($configPath); |
| 113 | - $selfIps = []; |
|
| 113 | + $selfIps = [ ]; |
|
| 114 | 114 | |
| 115 | 115 | // Look for other optional config files in the same directory |
| 116 | 116 | $selfIpsConfigPath = pathinfo($configPath, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . 'self_ips.json'; |
| 117 | - if (file_exists($selfIpsConfigPath)){ |
|
| 117 | + if (file_exists($selfIpsConfigPath)) { |
|
| 118 | 118 | $selfIps = self::loadJsonFile($selfIpsConfigPath)->self_ips; |
| 119 | 119 | } |
| 120 | 120 | |
@@ -146,17 +146,17 @@ discard block |
||
| 146 | 146 | public function report(string $ip = '', string $categories = '', string $message = '', bool $returnArray = false) |
| 147 | 147 | { |
| 148 | 148 | // ip must be set |
| 149 | - if (empty($ip)){ |
|
| 149 | + if (empty($ip)) { |
|
| 150 | 150 | throw new \InvalidArgumentException('Ip was empty'); |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // categories must be set |
| 154 | - if (empty($categories)){ |
|
| 154 | + if (empty($categories)) { |
|
| 155 | 155 | throw new \InvalidArgumentException('categories list was empty'); |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | // message must be set |
| 159 | - if (empty($message)){ |
|
| 159 | + if (empty($message)) { |
|
| 160 | 160 | throw new \InvalidArgumentException('report message was empty'); |
| 161 | 161 | } |
| 162 | 162 | |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | public function checkBlock(string $network = null, int $maxAge = 30, bool $returnArray = false) |
| 224 | 224 | { |
| 225 | 225 | // max age must be less or equal to 365 |
| 226 | - if ($maxAge > 365 || $maxAge < 1){ |
|
| 226 | + if ($maxAge > 365 || $maxAge < 1) { |
|
| 227 | 227 | throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)'); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | // ip must be set |
| 231 | - if (empty($network)){ |
|
| 231 | + if (empty($network)) { |
|
| 232 | 232 | throw new \InvalidArgumentException('network argument must be set (null given)'); |
| 233 | 233 | } |
| 234 | 234 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | 'maxAgeInDays' => $maxAge, |
| 239 | 239 | ]; |
| 240 | 240 | |
| 241 | - $response = $this->apiRequest('check-block', $data, 'GET', $returnArray) ; |
|
| 241 | + $response = $this->apiRequest('check-block', $data, 'GET', $returnArray); |
|
| 242 | 242 | |
| 243 | 243 | return json_decode($response, $returnArray); |
| 244 | 244 | } |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | public function clear(string $ip = null, bool $returnArray = false) |
| 266 | 266 | { |
| 267 | 267 | // ip must be set |
| 268 | - if (empty($ip)){ |
|
| 268 | + if (empty($ip)) { |
|
| 269 | 269 | throw new \InvalidArgumentException('ip argument must be set (null given)'); |
| 270 | 270 | } |
| 271 | 271 | |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | 'ipAddress' => $ip, |
| 275 | 275 | ]; |
| 276 | 276 | |
| 277 | - $response = $this->apiRequest('clear-address', $data, 'DELETE', $returnArray) ; |
|
| 277 | + $response = $this->apiRequest('clear-address', $data, 'DELETE', $returnArray); |
|
| 278 | 278 | |
| 279 | 279 | return json_decode($response, $returnArray); |
| 280 | 280 | } |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | public function check(string $ip = null, int $maxAge = 30, bool $verbose = false, bool $returnArray = false) |
| 295 | 295 | { |
| 296 | 296 | // max age must be less or equal to 365 |
| 297 | - if ($maxAge > 365 || $maxAge < 1){ |
|
| 297 | + if ($maxAge > 365 || $maxAge < 1) { |
|
| 298 | 298 | throw new \InvalidArgumentException('maxAge must be at least 1 and less than 365 (' . $maxAge . ' was given)'); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // ip must be set |
| 302 | - if (empty($ip)){ |
|
| 302 | + if (empty($ip)) { |
|
| 303 | 303 | throw new \InvalidArgumentException('ip argument must be set (null given)'); |
| 304 | 304 | } |
| 305 | 305 | |
@@ -310,11 +310,11 @@ discard block |
||
| 310 | 310 | ]; |
| 311 | 311 | |
| 312 | 312 | // option |
| 313 | - if ($verbose){ |
|
| 314 | - $data['verbose'] = true; |
|
| 313 | + if ($verbose) { |
|
| 314 | + $data[ 'verbose' ] = true; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - $response = $this->apiRequest('check', $data, 'GET', $returnArray) ; |
|
| 317 | + $response = $this->apiRequest('check', $data, 'GET', $returnArray); |
|
| 318 | 318 | |
| 319 | 319 | return json_decode($response, $returnArray); |
| 320 | 320 | } |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | public function getBlacklist(int $limit = 10000, bool $plainText = false, bool $returnArray = false) |
| 335 | 335 | { |
| 336 | 336 | |
| 337 | - if ($limit < 1){ |
|
| 337 | + if ($limit < 1) { |
|
| 338 | 338 | throw new \InvalidArgumentException('limit must be at least 1 (' . $limit . ' was given)'); |
| 339 | 339 | } |
| 340 | 340 | |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | |
| 347 | 347 | // plaintext paremeter has no value and must be added only when true |
| 348 | 348 | // (set plaintext=false won't work) |
| 349 | - if ($plainText){ |
|
| 350 | - $data['plaintext'] = $plainText; |
|
| 349 | + if ($plainText) { |
|
| 350 | + $data[ 'plaintext' ] = $plainText; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | $response = $this->apiRequest('blacklist', $data, 'GET'); |
| 354 | 354 | |
| 355 | - if ($plainText){ |
|
| 355 | + if ($plainText) { |
|
| 356 | 356 | return $response; |
| 357 | 357 | } |
| 358 | 358 | |
@@ -383,21 +383,21 @@ discard block |
||
| 383 | 383 | foreach ($cats as $cat) { |
| 384 | 384 | |
| 385 | 385 | // get index on our array of categories |
| 386 | - $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0); |
|
| 386 | + $catIndex = is_numeric($cat) ? $this->getCategoryIndex($cat, 1) : $this->getCategoryIndex($cat, 0); |
|
| 387 | 387 | |
| 388 | 388 | // check if found |
| 389 | - if ($catIndex === false ){ |
|
| 390 | - throw new \InvalidArgumentException('Invalid report category was given : ['. $cat . ']'); |
|
| 389 | + if ($catIndex === false) { |
|
| 390 | + throw new \InvalidArgumentException('Invalid report category was given : [' . $cat . ']'); |
|
| 391 | 391 | } |
| 392 | 392 | |
| 393 | 393 | // get Id |
| 394 | - $catId = $this->aipdbApiCategories[$catIndex][1]; |
|
| 394 | + $catId = $this->aipdbApiCategories[ $catIndex ][ 1 ]; |
|
| 395 | 395 | |
| 396 | 396 | // need another ? |
| 397 | - if ($needAnother !== false){ |
|
| 397 | + if ($needAnother !== false) { |
|
| 398 | 398 | |
| 399 | 399 | // is a standalone cat ? |
| 400 | - if ($this->aipdbApiCategories[$catIndex][3] === false) { |
|
| 400 | + if ($this->aipdbApiCategories[ $catIndex ][ 3 ] === false) { |
|
| 401 | 401 | $needAnother = true; |
| 402 | 402 | |
| 403 | 403 | } else { |
@@ -408,10 +408,10 @@ discard block |
||
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | // set or add to cats list |
| 411 | - $catsString = ($catsString === '') ? $catId : $catsString .','.$catId; |
|
| 411 | + $catsString = ($catsString === '') ? $catId : $catsString . ',' . $catId; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - if ($needAnother !== false){ |
|
| 414 | + if ($needAnother !== false) { |
|
| 415 | 415 | throw new \InvalidArgumentException('Invalid report category paremeter given: some categories can\'t be used alone'); |
| 416 | 416 | } |
| 417 | 417 | |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | $message = str_replace('\\', '', $message); |
| 484 | 484 | |
| 485 | 485 | // Remove self ips |
| 486 | - foreach ($this->selfIps as $ip){ |
|
| 486 | + foreach ($this->selfIps as $ip) { |
|
| 487 | 487 | $message = str_replace($ip, '*', $message); |
| 488 | 488 | } |
| 489 | 489 | |
@@ -510,7 +510,7 @@ discard block |
||
| 510 | 510 | protected static function loadJsonFile(string $filePath, bool $throwError = true) |
| 511 | 511 | { |
| 512 | 512 | // check file exists |
| 513 | - if (!file_exists($filePath) || !is_file($filePath)){ |
|
| 513 | + if (!file_exists($filePath) || !is_file($filePath)) { |
|
| 514 | 514 | if ($throwError) { |
| 515 | 515 | throw new \Exception('Config file not found'); |
| 516 | 516 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | $json = json_decode(utf8_encode($content)); |
| 523 | 523 | |
| 524 | 524 | // check for errors |
| 525 | - if ($json == null && json_last_error() != JSON_ERROR_NONE){ |
|
| 525 | + if ($json == null && json_last_error() != JSON_ERROR_NONE) { |
|
| 526 | 526 | if ($throwError) { |
| 527 | 527 | throw new \LogicException(sprintf("Failed to parse config file Error: '%s'", json_last_error_msg())); |
| 528 | 528 | } |