@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | public static function start(array $arguments, string $confPath): void |
47 | 47 | { |
48 | 48 | // required at least one valid argument |
49 | - self::validate( !empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
49 | + self::validate(!empty($arguments), 'No valid arguments given. Run abuseipdb --help to get help.'); |
|
50 | 50 | self::$configPath = $confPath; |
51 | 51 | if (!self::parseCommand($arguments, $confPath)) { |
52 | 52 | self::error('Invalid arguments. Run abuseipdb --help to get help.'); |
@@ -67,58 +67,58 @@ discard block |
||
67 | 67 | protected static function printHelp(): void |
68 | 68 | { |
69 | 69 | Console::log(); |
70 | - Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline')); |
|
71 | - Console::log(' ' . Console::text(' abuseipdb -C ') . |
|
72 | - Console::text('IP', 'yellow') . |
|
73 | - Console::text(' [-d ') . |
|
74 | - Console::text('DAYS', 'yellow') . |
|
75 | - Console::text('] [-v] [-l ') . |
|
76 | - Console::text('LIMIT', 'yellow') . |
|
77 | - Console::text('] [-o ') . |
|
78 | - Console::text('FORMAT', 'yellow') . |
|
70 | + Console::log(' '.Console::text('SYNOPSIS:', 'white', 'underline')); |
|
71 | + Console::log(' '.Console::text(' abuseipdb -C '). |
|
72 | + Console::text('IP', 'yellow'). |
|
73 | + Console::text(' [-d '). |
|
74 | + Console::text('DAYS', 'yellow'). |
|
75 | + Console::text('] [-v] [-l '). |
|
76 | + Console::text('LIMIT', 'yellow'). |
|
77 | + Console::text('] [-o '). |
|
78 | + Console::text('FORMAT', 'yellow'). |
|
79 | 79 | Console::text(']')); |
80 | 80 | |
81 | - Console::log(' ' . Console::text(' abuseipdb -K ') . |
|
82 | - Console::text('NETWORK', 'yellow') . |
|
83 | - Console::text(' [-d ') . |
|
84 | - Console::text('DAYS', 'yellow') . |
|
85 | - Console::text('] [-o ') . |
|
86 | - Console::text('FORMAT', 'yellow') . |
|
81 | + Console::log(' '.Console::text(' abuseipdb -K '). |
|
82 | + Console::text('NETWORK', 'yellow'). |
|
83 | + Console::text(' [-d '). |
|
84 | + Console::text('DAYS', 'yellow'). |
|
85 | + Console::text('] [-o '). |
|
86 | + Console::text('FORMAT', 'yellow'). |
|
87 | 87 | Console::text(']')); |
88 | 88 | |
89 | - Console::log(' ' . Console::text(' abuseipdb -R ') . |
|
90 | - Console::text('IP', 'yellow') . ' -c ' . |
|
91 | - Console::text('CATEGORIES', 'yellow') . ' -m ' . |
|
92 | - Console::text('MESSAGE', 'yellow') . |
|
93 | - Console::text(' [-o ') . |
|
94 | - Console::text('FORMAT', 'yellow') . |
|
89 | + Console::log(' '.Console::text(' abuseipdb -R '). |
|
90 | + Console::text('IP', 'yellow').' -c '. |
|
91 | + Console::text('CATEGORIES', 'yellow').' -m '. |
|
92 | + Console::text('MESSAGE', 'yellow'). |
|
93 | + Console::text(' [-o '). |
|
94 | + Console::text('FORMAT', 'yellow'). |
|
95 | 95 | Console::text(']')); |
96 | 96 | |
97 | - Console::log(' ' . Console::text(' abuseipdb -V ') . |
|
98 | - Console::text('FILE', 'yellow') . |
|
99 | - Console::text(' [-o ') . |
|
100 | - Console::text('FORMAT', 'yellow') . |
|
97 | + Console::log(' '.Console::text(' abuseipdb -V '). |
|
98 | + Console::text('FILE', 'yellow'). |
|
99 | + Console::text(' [-o '). |
|
100 | + Console::text('FORMAT', 'yellow'). |
|
101 | 101 | Console::text(']')); |
102 | 102 | |
103 | - Console::log(' ' . Console::text(' abuseipdb -E ') . |
|
103 | + Console::log(' '.Console::text(' abuseipdb -E '). |
|
104 | 104 | Console::text('IP', 'yellow'). |
105 | - Console::text(' [-o ') . |
|
106 | - Console::text('FORMAT', 'yellow') . |
|
105 | + Console::text(' [-o '). |
|
106 | + Console::text('FORMAT', 'yellow'). |
|
107 | 107 | Console::text(']')); |
108 | 108 | |
109 | - Console::log(' ' . Console::text(' abuseipdb -B ') . |
|
110 | - Console::text('[-l ') . |
|
111 | - Console::text('LIMIT', 'yellow') . |
|
112 | - Console::text('] [-s ') . |
|
113 | - Console::text('SCORE', 'yellow') . |
|
114 | - Console::text('] [-o ') . |
|
115 | - Console::text('FORMAT', 'yellow') . |
|
109 | + Console::log(' '.Console::text(' abuseipdb -B '). |
|
110 | + Console::text('[-l '). |
|
111 | + Console::text('LIMIT', 'yellow'). |
|
112 | + Console::text('] [-s '). |
|
113 | + Console::text('SCORE', 'yellow'). |
|
114 | + Console::text('] [-o '). |
|
115 | + Console::text('FORMAT', 'yellow'). |
|
116 | 116 | Console::text(']')); |
117 | 117 | |
118 | - Console::log(' ' . Console::text(' abuseipdb -L | -G | -h | --version')); |
|
118 | + Console::log(' '.Console::text(' abuseipdb -L | -G | -h | --version')); |
|
119 | 119 | |
120 | 120 | Console::log(); |
121 | - Console::log(' ' . Console::text('OPTIONS:', 'white', 'underline')); |
|
121 | + Console::log(' '.Console::text('OPTIONS:', 'white', 'underline')); |
|
122 | 122 | Console::log(); |
123 | 123 | Console::log(Console::text(' -h, --help', 'white')); |
124 | 124 | Console::log(' Prints the current help.', 'lightgray'); |
@@ -129,61 +129,61 @@ discard block |
||
129 | 129 | Console::log(Console::text(' -L, --list', 'white')); |
130 | 130 | Console::log(' Prints the list report categories.', 'lightgray'); |
131 | 131 | Console::log(); |
132 | - Console::log(Console::text(' -C, --check ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
132 | + Console::log(Console::text(' -C, --check ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
133 | 133 | Console::log(' Performs a check request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
134 | 134 | Console::log(); |
135 | - Console::log(Console::text(' -K, --check-block ', 'white') . Console::text('NETWORK', 'yellow', 'underline')); |
|
135 | + Console::log(Console::text(' -K, --check-block ', 'white').Console::text('NETWORK', 'yellow', 'underline')); |
|
136 | 136 | Console::log(' Performs a check-block request for the given network. A valid subnet (v4 or v6) denoted with ', 'lightgray'); |
137 | 137 | Console::log(' CIDR notation is required.', 'lightgray'); |
138 | 138 | Console::log(); |
139 | - Console::log(Console::text(' -d, --days ', 'white') . Console::text('DAYS', 'yellow', 'underline')); |
|
139 | + Console::log(Console::text(' -d, --days ', 'white').Console::text('DAYS', 'yellow', 'underline')); |
|
140 | 140 | Console::log(' For a check or check-block request, defines the maxAgeDays. Min is 1, max is 365, default is 30.', 'lightgray'); |
141 | 141 | Console::log(); |
142 | - Console::log(Console::text(' -R, --report ', 'white') . Console::text('IP', 'yellow', 'underline')); |
|
142 | + Console::log(Console::text(' -R, --report ', 'white').Console::text('IP', 'yellow', 'underline')); |
|
143 | 143 | Console::log(' Performs a report request for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
144 | 144 | Console::log(); |
145 | - Console::log(Console::text(' -V, --bulk-report ', 'white') . Console::text('FILE', 'yellow', 'underline')); |
|
145 | + Console::log(Console::text(' -V, --bulk-report ', 'white').Console::text('FILE', 'yellow', 'underline')); |
|
146 | 146 | Console::log(' Performs a bulk-report request sending a csv file. A valid file name or full path is required.', 'lightgray'); |
147 | 147 | Console::log(); |
148 | 148 | Console::log(Console::text(' -E, --clear ', 'white')); |
149 | 149 | Console::log(' Remove own reports for the given IP address. A valid IPv4 or IPv6 address is required.', 'lightgray'); |
150 | 150 | Console::log(); |
151 | - Console::log(Console::text(' -c, --categories ', 'white') . Console::text('CATEGORIES', 'yellow', 'underline')); |
|
151 | + Console::log(Console::text(' -c, --categories ', 'white').Console::text('CATEGORIES', 'yellow', 'underline')); |
|
152 | 152 | Console::log(' For a report request, defines the report category(ies). Categories must be separate by a comma.', 'lightgray'); |
153 | 153 | Console::log(' Some categories cannot be used alone. A category can be represented by its shortname or by its', 'lightgray'); |
154 | - Console::log(Console::text(' id. Use ','lightgray') . Console::text('abuseipdb -L', 'white') . Console::text(' to print the categories list.','lightgray')); |
|
154 | + Console::log(Console::text(' id. Use ', 'lightgray').Console::text('abuseipdb -L', 'white').Console::text(' to print the categories list.', 'lightgray')); |
|
155 | 155 | Console::log(); |
156 | - Console::log(Console::text(' -m, --message ', 'white') . Console::text('MESSAGE', 'yellow', 'underline')); |
|
156 | + Console::log(Console::text(' -m, --message ', 'white').Console::text('MESSAGE', 'yellow', 'underline')); |
|
157 | 157 | Console::log(' For a report request, defines the message to send with report. Message is required for all', 'lightgray'); |
158 | 158 | Console::log(' report requests.', 'lightgray'); |
159 | 159 | Console::log(); |
160 | 160 | Console::log(Console::text(' -B, --blacklist ', 'white')); |
161 | 161 | Console::log(' Performs a blacklist request. Default limit is 1000. This limit can ne changed with the', 'lightgray'); |
162 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
162 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
163 | 163 | Console::log(); |
164 | - Console::log(Console::text(' -l, --limit ', 'white') . Console::text('LIMIT', 'yellow', 'underline')); |
|
164 | + Console::log(Console::text(' -l, --limit ', 'white').Console::text('LIMIT', 'yellow', 'underline')); |
|
165 | 165 | Console::log(' For a blacklist request, defines the limit.', 'lightgray'); |
166 | 166 | Console::log(' For a check request with verbose flag, sets the max number of last reports displayed. Default is 10', 'lightgray'); |
167 | 167 | Console::log(' For a check-block request, sets the max number of IPs displayed. Default is 0 (no limit).', 'lightgray'); |
168 | 168 | Console::log(); |
169 | - Console::log(Console::text(' -o, --output ', 'white') . Console::text('FORMAT', 'yellow', 'underline')); |
|
169 | + Console::log(Console::text(' -o, --output ', 'white').Console::text('FORMAT', 'yellow', 'underline')); |
|
170 | 170 | Console::log(' Defines the output format for API requests. Default is a colorized report, possible formats are', 'lightgray'); |
171 | - Console::log(' '. Console::text('json', 'yellow', 'underline') . ' or ' . Console::text('plaintext', 'yellow', 'underline') . '. Plaintext option prints partial response (blacklist: IPs list, '); |
|
171 | + Console::log(' '.Console::text('json', 'yellow', 'underline').' or '.Console::text('plaintext', 'yellow', 'underline').'. Plaintext option prints partial response (blacklist: IPs list, '); |
|
172 | 172 | Console::log(' check or report: confidence score only, check-block: reported IPs list with confidence score, ', 'lightgray'); |
173 | 173 | Console::log(' bulk-report: number of saved reports, clear: number of deleted reports).', 'lightgray'); |
174 | 174 | Console::log(); |
175 | - Console::log(Console::text(' -s, --score ', 'white'). Console::text('SCORE', 'yellow', 'underline')); |
|
175 | + Console::log(Console::text(' -s, --score ', 'white').Console::text('SCORE', 'yellow', 'underline')); |
|
176 | 176 | Console::log(' For a blacklist request, sets the confidence score minimum. The confidence minimum ', 'lightgray'); |
177 | 177 | Console::log(' must be between 25 and 100. This parameter is subscriber feature (not honored otherwise, allways 100).', 'lightgray'); |
178 | 178 | Console::log(); |
179 | - Console::log(Console::text(' -t, --timeout ', 'white'). Console::text('TIMEOUT', 'yellow', 'underline')); |
|
179 | + Console::log(Console::text(' -t, --timeout ', 'white').Console::text('TIMEOUT', 'yellow', 'underline')); |
|
180 | 180 | Console::log(' Define the timeout in API request and overwrite the value defined in conf.ini or local.ini.', 'lightgray'); |
181 | 181 | Console::log(' Timeout is expressed in milliseconds.', 'lightgray'); |
182 | 182 | Console::log(); |
183 | 183 | Console::log(Console::text(' -v, --verbose ', 'white')); |
184 | 184 | Console::log(' For a check request, display additional fields like the x last reports. This increases ', 'lightgray'); |
185 | 185 | Console::log(Console::text(' request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray')); |
186 | - Console::log(' ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray')); |
|
186 | + Console::log(' '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray')); |
|
187 | 187 | Console::log(); |
188 | 188 | Console::log(Console::text(' --version', 'white')); |
189 | 189 | Console::log(' Prints the current version.', 'lightgray'); |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | |
206 | 206 | self::printTitle(Console::text(' ► Current configuration ', 'darkgray')); |
207 | 207 | |
208 | - Console::log(Console::text(' api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white')); |
|
209 | - Console::log(Console::text(' timeout:[', 'white') . Console::text($conf['timeout'], 'green') . Console::text(']', 'white')); |
|
208 | + Console::log(Console::text(' api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white')); |
|
209 | + Console::log(Console::text(' timeout:[', 'white').Console::text($conf['timeout'], 'green').Console::text(']', 'white')); |
|
210 | 210 | Console::log(Console::text(' self_ips:', 'white')); |
211 | 211 | |
212 | 212 | foreach ($conf['selfIps'] as $ip) { |
213 | - Console::log(Console::text(' [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white')); |
|
213 | + Console::log(Console::text(' [', 'white').Console::text($ip, 'green').Console::text(']', 'white')); |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | Console::log(); |
@@ -231,10 +231,10 @@ discard block |
||
231 | 231 | |
232 | 232 | $categories = ApiHandler::getCategories(); |
233 | 233 | $rowHeaders = [ |
234 | - Console::text('ShortName', 'darkgray') => 15, |
|
235 | - Console::text('Id', 'darkgray') => 2, |
|
236 | - Console::text('Full name', 'darkgray') => 18, |
|
237 | - Console::text('Can be alone?', 'darkgray') => 15 |
|
234 | + Console::text('ShortName', 'darkgray') => 15, |
|
235 | + Console::text('Id', 'darkgray') => 2, |
|
236 | + Console::text('Full name', 'darkgray') => 18, |
|
237 | + Console::text('Can be alone?', 'darkgray') => 15 |
|
238 | 238 | ]; |
239 | 239 | Console::$verticalSeparator = ' '; |
240 | 240 | Console::$verticalInnerSeparator = ' '; |
@@ -244,17 +244,16 @@ discard block |
||
244 | 244 | |
245 | 245 | foreach ($categories as $cat) { |
246 | 246 | $id = Console::text($cat[1], 'white'); |
247 | - $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') : |
|
248 | - Console::text('✗', 'red') . Console::text(' false', 'darkgray'); |
|
249 | - $shortName = Console::text($cat[0], 'white'); |
|
250 | - $fullName = Console::text($cat[2], 'lightgray'); |
|
247 | + $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray'); |
|
248 | + $shortName = Console::text($cat[0], 'white'); |
|
249 | + $fullName = Console::text($cat[2], 'lightgray'); |
|
251 | 250 | |
252 | 251 | Console::log( |
253 | 252 | Console::TableRowStart(). |
254 | - Console::TableRowCell( $shortName , 15). |
|
255 | - Console::TableRowCell( $id , 2, Console::ALIGN_CENTER). |
|
256 | - Console::TableRowCell( $fullName , 18). |
|
257 | - Console::TableRowCell( $standalone , 15, Console::ALIGN_CENTER) |
|
253 | + Console::TableRowCell($shortName, 15). |
|
254 | + Console::TableRowCell($id, 2, Console::ALIGN_CENTER). |
|
255 | + Console::TableRowCell($fullName, 18). |
|
256 | + Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER) |
|
258 | 257 | ); |
259 | 258 | } |
260 | 259 | //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray'); |
@@ -273,11 +272,11 @@ discard block |
||
273 | 272 | */ |
274 | 273 | protected static function reportIP(array $arguments): void |
275 | 274 | { |
276 | - $ip = self::getArgumentValue($arguments,'R', 'report'); |
|
277 | - $cats = self::getArgumentValue($arguments,'c', 'categories'); |
|
278 | - $message = self::getArgumentValue($arguments,'m', 'message'); |
|
275 | + $ip = self::getArgumentValue($arguments, 'R', 'report'); |
|
276 | + $cats = self::getArgumentValue($arguments, 'c', 'categories'); |
|
277 | + $message = self::getArgumentValue($arguments, 'm', 'message'); |
|
279 | 278 | |
280 | - self::printTitle(Console::text(' ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
279 | + self::printTitle(Console::text(' ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
281 | 280 | self::printTempMessage(); |
282 | 281 | |
283 | 282 | // Peforms request |
@@ -288,7 +287,7 @@ discard block |
||
288 | 287 | self::clearTempMessage(); |
289 | 288 | |
290 | 289 | // check for errors / empty response |
291 | - if (self::hasErrors($report)){ |
|
290 | + if (self::hasErrors($report)) { |
|
292 | 291 | self::printFooter(); |
293 | 292 | Program::exit(1); |
294 | 293 | } |
@@ -297,14 +296,14 @@ discard block |
||
297 | 296 | $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore; |
298 | 297 | $scoreColor = self::getScoreColor($score); |
299 | 298 | |
300 | - switch (self::$outputFormat){ |
|
299 | + switch (self::$outputFormat) { |
|
301 | 300 | case self::OUTPUT_JSON: |
302 | 301 | echo json_encode($report, JSON_PRETTY_PRINT); |
303 | 302 | break; |
304 | 303 | |
305 | 304 | case self::OUTPUT_DEFAULT: |
306 | 305 | Console::log( |
307 | - Console::text(' ✓', 'green').Console::text(' IP: [', 'white') . |
|
306 | + Console::text(' ✓', 'green').Console::text(' IP: [', 'white'). |
|
308 | 307 | Console::text($ip, $scoreColor).Console::text('] successfully reported', 'white') |
309 | 308 | ); |
310 | 309 | Console::log(Console::text(' Confidence score: ', 'white').self::getScoreBadge($score)); |
@@ -330,26 +329,26 @@ discard block |
||
330 | 329 | */ |
331 | 330 | protected static function bulkReport(array $arguments): void |
332 | 331 | { |
333 | - $fileName = self::getArgumentValue($arguments,'V', 'bulk-report'); |
|
332 | + $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report'); |
|
334 | 333 | |
335 | - self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white')); |
|
334 | + self::printTitle(Console::text(' ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white')); |
|
336 | 335 | self::printTempMessage(); |
337 | 336 | |
338 | 337 | // Peforms request |
339 | 338 | $timeStart = microtime(true); |
340 | 339 | $response = self::$api->bulkReport($fileName)->getObject(); |
341 | 340 | $timeEnd = microtime(true); |
342 | - $time = $timeEnd - $timeStart; // request time |
|
341 | + $time = $timeEnd - $timeStart; // request time |
|
343 | 342 | self::clearTempMessage(); |
344 | 343 | |
345 | 344 | // check for errors / empty response |
346 | - if (self::hasErrors($response)){ |
|
345 | + if (self::hasErrors($response)) { |
|
347 | 346 | self::printFooter(); |
348 | 347 | Program::exit(1); |
349 | 348 | } |
350 | 349 | |
351 | 350 | // ✓ Done |
352 | - switch (self::$outputFormat){ |
|
351 | + switch (self::$outputFormat) { |
|
353 | 352 | case self::OUTPUT_JSON: |
354 | 353 | echo json_encode($response, JSON_PRETTY_PRINT); |
355 | 354 | break; |
@@ -364,7 +363,7 @@ discard block |
||
364 | 363 | |
365 | 364 | case self::OUTPUT_PLAINTEXT: |
366 | 365 | $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0; |
367 | - echo $nbSavedReports . PHP_EOL; |
|
366 | + echo $nbSavedReports.PHP_EOL; |
|
368 | 367 | break; |
369 | 368 | |
370 | 369 | } |
@@ -381,8 +380,8 @@ discard block |
||
381 | 380 | */ |
382 | 381 | protected static function clearIP(array $arguments): void |
383 | 382 | { |
384 | - $ip = self::getArgumentValue($arguments,'E', 'clear'); |
|
385 | - self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white')); |
|
383 | + $ip = self::getArgumentValue($arguments, 'E', 'clear'); |
|
384 | + self::printTitle(Console::text(' ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white')); |
|
386 | 385 | |
387 | 386 | // Peforms request |
388 | 387 | self::printTempMessage(); |
@@ -393,22 +392,22 @@ discard block |
||
393 | 392 | self::clearTempMessage(); |
394 | 393 | |
395 | 394 | // check for errors / empty response |
396 | - if (self::hasErrors($response)){ |
|
395 | + if (self::hasErrors($response)) { |
|
397 | 396 | self::printFooter($time); |
398 | 397 | Program::exit(1); |
399 | 398 | } |
400 | 399 | |
401 | 400 | // ✓ Done: print deleted report number |
402 | - switch (self::$outputFormat){ |
|
401 | + switch (self::$outputFormat) { |
|
403 | 402 | case self::OUTPUT_JSON: |
404 | 403 | echo json_encode($response, JSON_PRETTY_PRINT); |
405 | 404 | break; |
406 | 405 | |
407 | 406 | case self::OUTPUT_DEFAULT: |
408 | 407 | Console::log( |
409 | - Console::text(' ✓', 'green') . |
|
410 | - Console::text(' Successfull clear request for IP: [', 'white') . |
|
411 | - Console::text($ip, 'lightyellow') . |
|
408 | + Console::text(' ✓', 'green'). |
|
409 | + Console::text(' Successfull clear request for IP: [', 'white'). |
|
410 | + Console::text($ip, 'lightyellow'). |
|
412 | 411 | Console::text(']', 'white') |
413 | 412 | ); |
414 | 413 | self::printResult(' Deleted reports: ', $response->data->numReportsDeleted ?? 0, 'lightyellow'); |
@@ -417,7 +416,7 @@ discard block |
||
417 | 416 | break; |
418 | 417 | |
419 | 418 | case self::OUTPUT_PLAINTEXT: |
420 | - echo ($response->data->numReportsDeleted ?? 0) . PHP_EOL; |
|
419 | + echo ($response->data->numReportsDeleted ?? 0).PHP_EOL; |
|
421 | 420 | break; |
422 | 421 | |
423 | 422 | } |
@@ -437,8 +436,8 @@ discard block |
||
437 | 436 | self::printTitle(Console::text(' ► Get Blacklist ', 'darkgray')); |
438 | 437 | |
439 | 438 | $plainText = (self::$outputFormat === self::OUTPUT_PLAINTEXT); |
440 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 1000); |
|
441 | - $scoreMin = self::getNumericParameter($arguments,'s', 'score', 100); |
|
439 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 1000); |
|
440 | + $scoreMin = self::getNumericParameter($arguments, 's', 'score', 100); |
|
442 | 441 | |
443 | 442 | self::printTempMessage(); |
444 | 443 | |
@@ -453,13 +452,13 @@ discard block |
||
453 | 452 | // response could be json on error, while plaintext flag is set |
454 | 453 | $decodedResponse = $response->getObject(); |
455 | 454 | |
456 | - if (self::hasErrors($decodedResponse, false)){ |
|
455 | + if (self::hasErrors($decodedResponse, false)) { |
|
457 | 456 | self::printFooter($time); |
458 | 457 | Program::exit(1); |
459 | 458 | } |
460 | 459 | |
461 | 460 | // ✓ Done: print deleted report number |
462 | - switch (self::$outputFormat){ |
|
461 | + switch (self::$outputFormat) { |
|
463 | 462 | case self::OUTPUT_JSON: |
464 | 463 | echo json_encode($decodedResponse, JSON_PRETTY_PRINT); |
465 | 464 | break; |
@@ -468,7 +467,7 @@ discard block |
||
468 | 467 | // print list |
469 | 468 | self::printResult(' List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', ''); |
470 | 469 | Console::log(); |
471 | - foreach ($decodedResponse->data as $report){ |
|
470 | + foreach ($decodedResponse->data as $report) { |
|
472 | 471 | $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore; |
473 | 472 | $defaultColor = self::getScoreColor($score); |
474 | 473 | |
@@ -503,12 +502,12 @@ discard block |
||
503 | 502 | */ |
504 | 503 | protected static function checkBlock(array $arguments): void |
505 | 504 | { |
506 | - $network = self::getArgumentValue($arguments,'K', 'check-block'); |
|
505 | + $network = self::getArgumentValue($arguments, 'K', 'check-block'); |
|
507 | 506 | |
508 | - self::printTitle(Console::text(' ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray')); |
|
507 | + self::printTitle(Console::text(' ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray')); |
|
509 | 508 | |
510 | 509 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
511 | - $limit = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit |
|
510 | + $limit = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit |
|
512 | 511 | |
513 | 512 | self::printTempMessage(); |
514 | 513 | |
@@ -519,19 +518,19 @@ discard block |
||
519 | 518 | self::clearTempMessage(); |
520 | 519 | |
521 | 520 | // check for errors / empty response |
522 | - if (self::hasErrors($check)){ |
|
521 | + if (self::hasErrors($check)) { |
|
523 | 522 | self::printFooter($time); |
524 | 523 | Program::exit(1); |
525 | 524 | } |
526 | 525 | |
527 | - switch (self::$outputFormat){ |
|
526 | + switch (self::$outputFormat) { |
|
528 | 527 | case self::OUTPUT_JSON: |
529 | 528 | echo json_encode($check, JSON_PRETTY_PRINT); |
530 | 529 | break; |
531 | 530 | |
532 | 531 | case self::OUTPUT_DEFAULT: |
533 | 532 | self::printCheckBlockDetail($check); |
534 | - self::printCheckBlockReportedIP($check,$maxAge,$limit); |
|
533 | + self::printCheckBlockReportedIP($check, $maxAge, $limit); |
|
535 | 534 | Console::log(); |
536 | 535 | self::printFooter($time); |
537 | 536 | break; |
@@ -540,8 +539,8 @@ discard block |
||
540 | 539 | $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0; |
541 | 540 | if ($nbReports > 0) { |
542 | 541 | $numberDiplayedReports = 0; |
543 | - foreach ($check->data->reportedAddress as $report){ |
|
544 | - echo ($report->ipAddress) . ' ' . $report->abuseConfidenceScore . PHP_EOL; |
|
542 | + foreach ($check->data->reportedAddress as $report) { |
|
543 | + echo ($report->ipAddress).' '.$report->abuseConfidenceScore.PHP_EOL; |
|
545 | 544 | |
546 | 545 | // counter |
547 | 546 | $numberDiplayedReports++; |
@@ -565,14 +564,14 @@ discard block |
||
565 | 564 | */ |
566 | 565 | protected static function checkIP(array $arguments): void |
567 | 566 | { |
568 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
567 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
569 | 568 | |
570 | - self::printTitle(Console::text(' ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray')); |
|
569 | + self::printTitle(Console::text(' ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray')); |
|
571 | 570 | |
572 | - $verbose = self::inArguments($arguments,'v', 'verbose'); |
|
571 | + $verbose = self::inArguments($arguments, 'v', 'verbose'); |
|
573 | 572 | $maxAge = self::getNumericParameter($arguments, 'd', 'days', 30); |
574 | - $maxReportsNumber = self::getNumericParameter($arguments,'l', 'limit', 10); |
|
575 | - $ip = self::getArgumentValue($arguments,'C', 'check'); |
|
573 | + $maxReportsNumber = self::getNumericParameter($arguments, 'l', 'limit', 10); |
|
574 | + $ip = self::getArgumentValue($arguments, 'C', 'check'); |
|
576 | 575 | |
577 | 576 | self::printTempMessage(); |
578 | 577 | $timeStart = microtime(true); |
@@ -582,7 +581,7 @@ discard block |
||
582 | 581 | self::clearTempMessage(); |
583 | 582 | |
584 | 583 | // check for errors / empty response |
585 | - if (self::hasErrors($check)){ |
|
584 | + if (self::hasErrors($check)) { |
|
586 | 585 | self::printFooter($time); |
587 | 586 | Program::exit(1); |
588 | 587 | } |
@@ -590,7 +589,7 @@ discard block |
||
590 | 589 | // score and data color (depending of abuseConfidenceScore) |
591 | 590 | $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore; |
592 | 591 | |
593 | - switch (self::$outputFormat){ |
|
592 | + switch (self::$outputFormat) { |
|
594 | 593 | case self::OUTPUT_JSON: |
595 | 594 | echo json_encode($check, JSON_PRETTY_PRINT); |
596 | 595 | break; |
@@ -600,7 +599,7 @@ discard block |
||
600 | 599 | self::printCheckScore($check); |
601 | 600 | self::printCheckDetail($check, $defaultColor); |
602 | 601 | self::printCheckReports($check, $maxAge, $defaultColor); |
603 | - if ($verbose){ |
|
602 | + if ($verbose) { |
|
604 | 603 | self::printCheckLastReports($check, $maxReportsNumber); |
605 | 604 | } |
606 | 605 | Console::log(); |
@@ -608,7 +607,7 @@ discard block |
||
608 | 607 | break; |
609 | 608 | |
610 | 609 | case self::OUTPUT_PLAINTEXT: |
611 | - echo ($check->data->abuseConfidenceScore ?? 0) . PHP_EOL; |
|
610 | + echo ($check->data->abuseConfidenceScore ?? 0).PHP_EOL; |
|
612 | 611 | break; |
613 | 612 | |
614 | 613 | } |
@@ -36,17 +36,17 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var string |
38 | 38 | */ |
39 | - const OUTPUT_JSON = 'json'; |
|
39 | + const OUTPUT_JSON = 'json'; |
|
40 | 40 | |
41 | 41 | /** |
42 | 42 | * @var string |
43 | 43 | */ |
44 | - const OUTPUT_DEFAULT = 'default'; |
|
44 | + const OUTPUT_DEFAULT = 'default'; |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * @var string |
48 | 48 | */ |
49 | - const OUTPUT_PLAINTEXT = 'plaintext'; |
|
49 | + const OUTPUT_PLAINTEXT = 'plaintext'; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @var string $outputFormat |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | protected static function printTempMessage(): void |
92 | 92 | { |
93 | 93 | if (self::isDefaultOuput()) { |
94 | - Console::reLog(Console::text(' ? ', 'green') . Console::text('waiting for api response', 'white') . Console::text(' ... ', 'green')); |
|
94 | + Console::reLog(Console::text(' ? ', 'green').Console::text('waiting for api response', 'white').Console::text(' ... ', 'green')); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -145,10 +145,10 @@ discard block |
||
145 | 145 | self::printLogo(); |
146 | 146 | |
147 | 147 | Console::log(); |
148 | - Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray') . Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
149 | - Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray') . Console::text(ApiHandler::VERSION, 'lightgray')); |
|
148 | + Console::log(Console::text(' Kristuff/AbuseIPDB Client version: ', 'darkgray').Console::text(AbuseIPDBClient::VERSION, 'lightgray')); |
|
149 | + Console::log(Console::text(' Kristuff/AbuseIPDB Core version: ', 'darkgray').Console::text(ApiHandler::VERSION, 'lightgray')); |
|
150 | 150 | Console::log(Console::text(' Released under the MIT licence', 'darkgray')); |
151 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
151 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
152 | 152 | Console::log( |
153 | 153 | Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
154 | 154 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
@@ -170,8 +170,8 @@ discard block |
||
170 | 170 | { |
171 | 171 | if (self::isDefaultOuput()) { |
172 | 172 | Console::log(); |
173 | - Console::log( Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray') . Console::text(' ' . AbuseIPDBClient::VERSION . ' ', 'white', 'blue')); |
|
174 | - Console::log(Console::text(' Made with ', 'darkgray') . Console::text('♥', 'red') . Console::text(' in France', 'darkgray')); |
|
173 | + Console::log(Console::text(' Kristuff/AbuseIPDB-client ', 'darkgray').Console::text(' '.AbuseIPDBClient::VERSION.' ', 'white', 'blue')); |
|
174 | + Console::log(Console::text(' Made with ', 'darkgray').Console::text('♥', 'red').Console::text(' in France', 'darkgray')); |
|
175 | 175 | Console::log(Console::text(' © 2020-2021 Kristuff (', 'darkgray'). |
176 | 176 | Console::text('https://github.com/kristuff', 'darkgray', 'underlined'). |
177 | 177 | Console::text(')', 'darkgray') |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | protected static function printFooter($requestTime = ''): void |
192 | 192 | { |
193 | 193 | if (self::isDefaultOuput()) { |
194 | - if (!empty($requestTime)){ |
|
194 | + if (!empty($requestTime)) { |
|
195 | 195 | $date_utc = new \DateTime("now", new \DateTimeZone("UTC")); |
196 | 196 | Console::log( |
197 | - Console::text(' Request time: ', 'darkgray') . Console::text($requestTime . 's', 'lightgray'). |
|
198 | - Console::text(' | UTC time: ', 'darkgray') . Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
197 | + Console::text(' Request time: ', 'darkgray').Console::text($requestTime.'s', 'lightgray'). |
|
198 | + Console::text(' | UTC time: ', 'darkgray').Console::text($date_utc->format('Y-m-d H:i:s'), 'lightgray') |
|
199 | 199 | ); |
200 | 200 | } |
201 | 201 | Console::log(Console::text(' ------------------------------------------------------------------------------------------------------', 'darkgray')); |
202 | 202 | Console::log( |
203 | - Console::text(' Kristuff\AbuseIPDB ', 'darkgray') . |
|
204 | - Console::text(AbuseIPDBClient::VERSION, 'lightgray') . |
|
205 | - Console::text(' | Made with ', 'darkgray') . |
|
206 | - Console::text('♥', 'red') . |
|
203 | + Console::text(' Kristuff\AbuseIPDB ', 'darkgray'). |
|
204 | + Console::text(AbuseIPDBClient::VERSION, 'lightgray'). |
|
205 | + Console::text(' | Made with ', 'darkgray'). |
|
206 | + Console::text('♥', 'red'). |
|
207 | 207 | Console::text(' in France | © 2020-2021 Kristuff (https://github.com/kristuff)', 'darkgray') |
208 | 208 | ); |
209 | 209 | Console::log(); |
@@ -221,9 +221,9 @@ discard block |
||
221 | 221 | protected static function printResult($text, $value, string $foregroundColor = 'lightred', string $backgroundColor = '', bool $print = true): string |
222 | 222 | { |
223 | 223 | // do not print null/blank values |
224 | - if (isset($value)){ |
|
225 | - $line = Console::text($text, 'white') . Console::text($value, $foregroundColor, $backgroundColor); |
|
226 | - if ($print && self::isDefaultOuput()){ |
|
224 | + if (isset($value)) { |
|
225 | + $line = Console::text($text, 'white').Console::text($value, $foregroundColor, $backgroundColor); |
|
226 | + if ($print && self::isDefaultOuput()) { |
|
227 | 227 | Console::log($line); |
228 | 228 | } |
229 | 229 | return $line; |
@@ -247,16 +247,16 @@ discard block |
||
247 | 247 | $scoreforegroundColor = 'white'; |
248 | 248 | $scoreBackgroundColor = 'green'; |
249 | 249 | |
250 | - if (intval($score) > 0 ){ |
|
250 | + if (intval($score) > 0) { |
|
251 | 251 | $scoreforegroundColor = 'black'; |
252 | 252 | $scoreBackgroundColor = 'yellow'; |
253 | 253 | } |
254 | - if (intval($score) > 50 ){ |
|
254 | + if (intval($score) > 50) { |
|
255 | 255 | $scoreforegroundColor = 'white'; |
256 | 256 | $scoreBackgroundColor = 'red'; |
257 | 257 | } |
258 | 258 | |
259 | - $badge = str_pad(strval($score), 3, ' ',STR_PAD_LEFT); |
|
259 | + $badge = str_pad(strval($score), 3, ' ', STR_PAD_LEFT); |
|
260 | 260 | return Console::text($padding.$badge.$padding, $scoreforegroundColor, $scoreBackgroundColor); |
261 | 261 | } |
262 | 262 | } |
263 | 263 | \ No newline at end of file |
@@ -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', '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 []; |