@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @var string |
| 38 | 38 | */ |
| 39 | - const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:',' bulk-report:', 'help', 'verbose', 'score:', 'version']; |
|
| 39 | + const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:', ' bulk-report:', 'help', 'verbose', 'score:', 'version']; |
|
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | 42 | * @var string |
@@ -57,22 +57,22 @@ discard block |
||
| 57 | 57 | * @var array |
| 58 | 58 | */ |
| 59 | 59 | protected static $basicCommands = [ |
| 60 | - ['h', 'help', 'printHelp'], |
|
| 61 | - ['version', 'version', 'printVersion'], // no short arg |
|
| 62 | - ['L', 'list', 'printCategories'], |
|
| 60 | + ['h', 'help', 'printHelp'], |
|
| 61 | + ['version', 'version', 'printVersion'], // no short arg |
|
| 62 | + ['L', 'list', 'printCategories'], |
|
| 63 | 63 | ]; |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | 66 | * @var array |
| 67 | 67 | */ |
| 68 | 68 | protected static $mainCommands = [ |
| 69 | - ['G', 'config', 'printConfig'], // require handler |
|
| 70 | - ['C', 'check', 'checkIP'], |
|
| 71 | - ['K', 'check-block', 'checkBlock'], |
|
| 72 | - ['R', 'report', 'reportIP'], |
|
| 73 | - ['V', 'bulk-report', 'bulkReport'], |
|
| 74 | - ['B', 'blacklist', 'getBlacklist'], |
|
| 75 | - ['E', 'clear', 'clearIP'], |
|
| 69 | + ['G', 'config', 'printConfig'], // require handler |
|
| 70 | + ['C', 'check', 'checkIP'], |
|
| 71 | + ['K', 'check-block', 'checkBlock'], |
|
| 72 | + ['R', 'report', 'reportIP'], |
|
| 73 | + ['V', 'bulk-report', 'bulkReport'], |
|
| 74 | + ['B', 'blacklist', 'getBlacklist'], |
|
| 75 | + ['E', 'clear', 'clearIP'], |
|
| 76 | 76 | ]; |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -86,14 +86,14 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | protected static function parseCommand(array $arguments): bool |
| 88 | 88 | { |
| 89 | - foreach(self::$basicCommands as $cmd){ |
|
| 90 | - if (self::inArguments($arguments, $cmd[0], $cmd[1])){ |
|
| 89 | + foreach (self::$basicCommands as $cmd) { |
|
| 90 | + if (self::inArguments($arguments, $cmd[0], $cmd[1])) { |
|
| 91 | 91 | call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], null); |
| 92 | 92 | return true; |
| 93 | 93 | } |
| 94 | 94 | } |
| 95 | - foreach(self::$mainCommands as $cmd){ |
|
| 96 | - if (self::inArguments($arguments, $cmd[0], $cmd[1])){ |
|
| 95 | + foreach (self::$mainCommands as $cmd) { |
|
| 96 | + if (self::inArguments($arguments, $cmd[0], $cmd[1])) { |
|
| 97 | 97 | self::createHandler(); |
| 98 | 98 | self::setOutputFormat($arguments); |
| 99 | 99 | call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], $arguments); |
@@ -131,8 +131,8 @@ discard block |
||
| 131 | 131 | protected static function createHandler(): void |
| 132 | 132 | { |
| 133 | 133 | try { |
| 134 | - $mainConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'conf.ini'; |
|
| 135 | - $localConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'local.ini'; |
|
| 134 | + $mainConfPath = self::$configPath.DIRECTORY_SEPARATOR.'conf.ini'; |
|
| 135 | + $localConfPath = self::$configPath.DIRECTORY_SEPARATOR.'local.ini'; |
|
| 136 | 136 | |
| 137 | 137 | // Check main file exists and is readable |
| 138 | 138 | // Even if a local file exists, main file must be here (throws ex otherwise) |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $selfIps = self::extractSelfIpsFromConf($mainConfigArray, $localConfigArray); |
| 143 | 143 | $apiKey = self::extractApiKeyFromConf($mainConfigArray, $localConfigArray); |
| 144 | 144 | |
| 145 | - self::$api = new QuietApiHandler($apiKey, $selfIps); |
|
| 145 | + self::$api = new QuietApiHandler($apiKey, $selfIps); |
|
| 146 | 146 | } catch (\Exception $e) { |
| 147 | 147 | self::error($e->getMessage()); |
| 148 | 148 | self::printFooter(); |
@@ -162,10 +162,10 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | protected static function extractSelfIpsFromConf(array $conf, array $localConf): array |
| 164 | 164 | { |
| 165 | - if (array_key_exists('self_ips', $localConf) && !empty($localConf['self_ips'])){ |
|
| 165 | + if (array_key_exists('self_ips', $localConf) && !empty($localConf['self_ips'])) { |
|
| 166 | 166 | return array_map('trim', explode(',', $localConf['self_ips'])); |
| 167 | 167 | } |
| 168 | - if (array_key_exists('self_ips', $conf) && !empty($conf['self_ips'])){ |
|
| 168 | + if (array_key_exists('self_ips', $conf) && !empty($conf['self_ips'])) { |
|
| 169 | 169 | return array_map('trim', explode(',', $conf['self_ips'])); |
| 170 | 170 | } |
| 171 | 171 | return []; |
@@ -186,15 +186,15 @@ discard block |
||
| 186 | 186 | { |
| 187 | 187 | $key = ''; |
| 188 | 188 | |
| 189 | - if (array_key_exists('api_key', $localConf)){ |
|
| 189 | + if (array_key_exists('api_key', $localConf)) { |
|
| 190 | 190 | $key = $localConf['api_key']; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - if (empty($key) && array_key_exists('api_key', $conf)){ |
|
| 193 | + if (empty($key) && array_key_exists('api_key', $conf)) { |
|
| 194 | 194 | $key = $conf['api_key']; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - if (empty($key)){ |
|
| 197 | + if (empty($key)) { |
|
| 198 | 198 | throw new \RuntimeException('Api key is missing.'); |
| 199 | 199 | } |
| 200 | 200 | |
@@ -214,21 +214,21 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected static function loadConfigFile(string $path, bool $mandatory = false): array |
| 216 | 216 | { |
| 217 | - if (file_exists($path) && is_file($path)){ |
|
| 217 | + if (file_exists($path) && is_file($path)) { |
|
| 218 | 218 | |
| 219 | 219 | // If main file or a local file is not readable then throws ex. |
| 220 | - if (!is_readable($path)){ |
|
| 220 | + if (!is_readable($path)) { |
|
| 221 | 221 | throw new \RuntimeException('The configuration file ['.$path.'] is not readable.'); |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - $conf = parse_ini_file($path, false); // load without sections... |
|
| 225 | - if ($conf === false){ |
|
| 224 | + $conf = parse_ini_file($path, false); // load without sections... |
|
| 225 | + if ($conf === false) { |
|
| 226 | 226 | throw new \RuntimeException('Unable to read configuration file ['.$path.'].'); |
| 227 | 227 | } |
| 228 | 228 | return $conf; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if ($mandatory){ |
|
| 231 | + if ($mandatory) { |
|
| 232 | 232 | throw new \RuntimeException('The configuration file ['.$path.'] does not exist.'); |
| 233 | 233 | } |
| 234 | 234 | return []; |