@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | /** |
| 37 | 37 | * @var array |
| 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', 'timeout:']; |
|
| 39 | + const LONG_ARGUMENTS = ['output:', 'config', 'list', 'blacklist', 'check:', 'check-block:', 'days:', 'report:', 'categories:', 'message:', 'limit:', 'clear:', ' bulk-report:', 'help', 'verbose', 'score:', 'version', 'timeout:']; |
|
| 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($arguments); |
| 98 | 98 | self::setOutputFormat($arguments); |
| 99 | 99 | call_user_func(__NAMESPACE__.'\AbuseIPDBClient::'.$cmd[2], $arguments); |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | protected static function createHandler(array $arguments): void |
| 133 | 133 | { |
| 134 | 134 | try { |
| 135 | - $mainConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'conf.ini'; |
|
| 136 | - $localConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'local.ini'; |
|
| 135 | + $mainConfPath = self::$configPath.DIRECTORY_SEPARATOR.'conf.ini'; |
|
| 136 | + $localConfPath = self::$configPath.DIRECTORY_SEPARATOR.'local.ini'; |
|
| 137 | 137 | |
| 138 | 138 | // Check main file exists and is readable |
| 139 | 139 | // Even if a local file exists, main file must be here (throws ex otherwise) |
@@ -142,18 +142,18 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | $selfIps = self::extractSelfIpsFromConf($mainConfigArray, $localConfigArray); |
| 144 | 144 | $apiKey = self::extractApiKeyFromConf($mainConfigArray, $localConfigArray); |
| 145 | - $timeout = self::extractNumericFromConf('timeout',$mainConfigArray, $localConfigArray, 0); |
|
| 145 | + $timeout = self::extractNumericFromConf('timeout', $mainConfigArray, $localConfigArray, 0); |
|
| 146 | 146 | |
| 147 | 147 | // look into arguments for possible overwrite for timeout |
| 148 | - if (self::inArguments($arguments, 't', 'timeout')){ |
|
| 148 | + if (self::inArguments($arguments, 't', 'timeout')) { |
|
| 149 | 149 | $timeout = self::getArgumentValue($arguments, 't', 'timeout'); |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - if (!is_numeric($timeout)){ |
|
| 152 | + if (!is_numeric($timeout)) { |
|
| 153 | 153 | throw new \RuntimeException('Invalid timeout argument, must be numeric.'); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - self::$api = new QuietApiHandler($apiKey, $selfIps, intval($timeout)); |
|
| 156 | + self::$api = new QuietApiHandler($apiKey, $selfIps, intval($timeout)); |
|
| 157 | 157 | } catch (\Exception $e) { |
| 158 | 158 | self::error($e->getMessage()); |
| 159 | 159 | self::printFooter(); |
@@ -173,10 +173,10 @@ discard block |
||
| 173 | 173 | */ |
| 174 | 174 | protected static function extractSelfIpsFromConf(array $conf, array $localConf): array |
| 175 | 175 | { |
| 176 | - if (array_key_exists('self_ips', $localConf) && !empty($localConf['self_ips'])){ |
|
| 176 | + if (array_key_exists('self_ips', $localConf) && !empty($localConf['self_ips'])) { |
|
| 177 | 177 | return array_map('trim', explode(',', $localConf['self_ips'])); |
| 178 | 178 | } |
| 179 | - if (array_key_exists('self_ips', $conf) && !empty($conf['self_ips'])){ |
|
| 179 | + if (array_key_exists('self_ips', $conf) && !empty($conf['self_ips'])) { |
|
| 180 | 180 | return array_map('trim', explode(',', $conf['self_ips'])); |
| 181 | 181 | } |
| 182 | 182 | return []; |
@@ -197,15 +197,15 @@ discard block |
||
| 197 | 197 | { |
| 198 | 198 | $key = ''; |
| 199 | 199 | |
| 200 | - if (array_key_exists('api_key', $localConf)){ |
|
| 200 | + if (array_key_exists('api_key', $localConf)) { |
|
| 201 | 201 | $key = $localConf['api_key']; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if (empty($key) && array_key_exists('api_key', $conf)){ |
|
| 204 | + if (empty($key) && array_key_exists('api_key', $conf)) { |
|
| 205 | 205 | $key = $conf['api_key']; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if (empty($key)){ |
|
| 208 | + if (empty($key)) { |
|
| 209 | 209 | throw new \RuntimeException('Api key is missing.'); |
| 210 | 210 | } |
| 211 | 211 | |
@@ -226,11 +226,11 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | protected static function extractNumericFromConf(string $key, array $conf, array $localConf, int $default): int |
| 228 | 228 | { |
| 229 | - if (array_key_exists($key, $localConf) && is_numeric($localConf[$key])){ |
|
| 229 | + if (array_key_exists($key, $localConf) && is_numeric($localConf[$key])) { |
|
| 230 | 230 | return intval($localConf[$key]); |
| 231 | 231 | } |
| 232 | 232 | |
| 233 | - if (array_key_exists($key, $conf) && is_numeric($conf[$key])){ |
|
| 233 | + if (array_key_exists($key, $conf) && is_numeric($conf[$key])) { |
|
| 234 | 234 | return intval($conf[$key]); |
| 235 | 235 | } |
| 236 | 236 | |
@@ -250,21 +250,21 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | protected static function loadConfigFile(string $path, bool $mandatory = false): array |
| 252 | 252 | { |
| 253 | - if (file_exists($path) && is_file($path)){ |
|
| 253 | + if (file_exists($path) && is_file($path)) { |
|
| 254 | 254 | |
| 255 | 255 | // If main file or a local file is not readable then throws ex. |
| 256 | - if (!is_readable($path)){ |
|
| 256 | + if (!is_readable($path)) { |
|
| 257 | 257 | throw new \RuntimeException('The configuration file ['.$path.'] is not readable.'); |
| 258 | 258 | } |
| 259 | 259 | |
| 260 | - $conf = parse_ini_file($path, false); // load without sections... |
|
| 261 | - if ($conf === false){ |
|
| 260 | + $conf = parse_ini_file($path, false); // load without sections... |
|
| 261 | + if ($conf === false) { |
|
| 262 | 262 | throw new \RuntimeException('Unable to read configuration file ['.$path.'].'); |
| 263 | 263 | } |
| 264 | 264 | return $conf; |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if ($mandatory){ |
|
| 267 | + if ($mandatory) { |
|
| 268 | 268 | throw new \RuntimeException('The configuration file ['.$path.'] does not exist.'); |
| 269 | 269 | } |
| 270 | 270 | return []; |