Passed
Branch master (eefaca)
by Kris
01:57
created
src/AbuseIPDBClient.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -69,51 +69,51 @@
 block discarded – undo
69 69
         Console::log();
70 70
         Console::log(' ' . Console::text('SYNOPSIS:', 'white', 'underline')); 
71 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
-                           Console::text(']')); 
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
+                            Console::text(']')); 
80 80
 
81 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
-                           Console::text(']')); 
82
+                            Console::text('NETWORK', 'yellow') . 
83
+                            Console::text(' [-d ') . 
84
+                            Console::text('DAYS', 'yellow') . 
85
+                            Console::text('] [-o ') . 
86
+                            Console::text('FORMAT', 'yellow') . 
87
+                            Console::text(']')); 
88 88
 
89 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
-                           Console::text(']')); 
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
+                            Console::text(']')); 
96 96
 
97 97
         Console::log(' ' . Console::text('    abuseipdb -V ') .
98
-                           Console::text('FILE', 'yellow') .
99
-                           Console::text(' [-o ') . 
100
-                           Console::text('FORMAT', 'yellow') . 
101
-                           Console::text(']')); 
98
+                            Console::text('FILE', 'yellow') .
99
+                            Console::text(' [-o ') . 
100
+                            Console::text('FORMAT', 'yellow') . 
101
+                            Console::text(']')); 
102 102
 
103 103
         Console::log(' ' . Console::text('    abuseipdb -E ') .
104
-                           Console::text('IP', 'yellow').
105
-                           Console::text(' [-o ') . 
106
-                           Console::text('FORMAT', 'yellow') . 
107
-                           Console::text(']')); 
104
+                            Console::text('IP', 'yellow').
105
+                            Console::text(' [-o ') . 
106
+                            Console::text('FORMAT', 'yellow') . 
107
+                            Console::text(']')); 
108 108
                            
109 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
-                           Console::text(']')); 
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
+                            Console::text(']')); 
117 117
 
118 118
         Console::log(' ' . Console::text('    abuseipdb -L | -G | -h | --version'));
119 119
                            
Please login to merge, or discard this patch.
Spacing   +108 added lines, -109 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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,57 +129,57 @@  discard block
 block discarded – undo
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 179
         Console::log(Console::text('   -v, --verbose ', 'white')); 
180 180
         Console::log('       For a check request, display additional fields like the x last reports. This increases ', 'lightgray');
181 181
         Console::log(Console::text('       request time and response size. Max number of last reports displayed can be changed with the ', 'lightgray'));
182
-        Console::log('       ' . Console::text('--limit', 'white') . Console::text(' parameter. ', 'lightgray'));
182
+        Console::log('       '.Console::text('--limit', 'white').Console::text(' parameter. ', 'lightgray'));
183 183
         Console::log();    
184 184
         Console::log(Console::text('   --version', 'white')); 
185 185
         Console::log('       Prints the current version.', 'lightgray');
@@ -201,11 +201,11 @@  discard block
 block discarded – undo
201 201
 
202 202
         self::printTitle(Console::text('  ► Current configuration ', 'darkgray'));
203 203
         
204
-        Console::log(Console::text('  api_key:[', 'white') . Console::text($conf['apiKey'], 'green') . Console::text(']', 'white'));
204
+        Console::log(Console::text('  api_key:[', 'white').Console::text($conf['apiKey'], 'green').Console::text(']', 'white'));
205 205
         Console::log(Console::text('  self_ips:', 'white'));
206 206
         
207 207
         foreach ($conf['selfIps'] as $ip) {
208
-            Console::log(Console::text('    [', 'white') . Console::text($ip, 'green') . Console::text(']', 'white'));   
208
+            Console::log(Console::text('    [', 'white').Console::text($ip, 'green').Console::text(']', 'white'));   
209 209
         }
210 210
 
211 211
         Console::log();   
@@ -226,10 +226,10 @@  discard block
 block discarded – undo
226 226
 
227 227
         $categories = ApiHandler::getCategories();
228 228
         $rowHeaders = [
229
-            Console::text('ShortName',      'darkgray') => 15, 
230
-            Console::text('Id',             'darkgray') => 2, 
231
-            Console::text('Full name',      'darkgray') => 18,
232
-            Console::text('Can be alone?',  'darkgray') => 15
229
+            Console::text('ShortName', 'darkgray') => 15, 
230
+            Console::text('Id', 'darkgray') => 2, 
231
+            Console::text('Full name', 'darkgray') => 18,
232
+            Console::text('Can be alone?', 'darkgray') => 15
233 233
         ];
234 234
         Console::$verticalSeparator = '  ';
235 235
         Console::$verticalInnerSeparator = '  ';
@@ -239,17 +239,16 @@  discard block
 block discarded – undo
239 239
         
240 240
         foreach ($categories as $cat) {
241 241
             $id = Console::text($cat[1], 'white');
242
-            $standalone = $cat[3] ? Console::text('✓', 'green') . Console::text(' true ', 'lightgray') : 
243
-                                    Console::text('✗', 'red')   . Console::text(' false', 'darkgray');
244
-            $shortName =  Console::text($cat[0], 'white');
245
-            $fullName =   Console::text($cat[2], 'lightgray');
242
+            $standalone = $cat[3] ? Console::text('✓', 'green').Console::text(' true ', 'lightgray') : Console::text('✗', 'red').Console::text(' false', 'darkgray');
243
+            $shortName = Console::text($cat[0], 'white');
244
+            $fullName = Console::text($cat[2], 'lightgray');
246 245
 
247 246
             Console::log(
248 247
                 Console::TableRowStart().  
249
-                Console::TableRowCell( $shortName , 15).  
250
-                Console::TableRowCell( $id , 2, Console::ALIGN_CENTER).  
251
-                Console::TableRowCell( $fullName , 18).  
252
-                Console::TableRowCell( $standalone , 15,  Console::ALIGN_CENTER)  
248
+                Console::TableRowCell($shortName, 15).  
249
+                Console::TableRowCell($id, 2, Console::ALIGN_CENTER).  
250
+                Console::TableRowCell($fullName, 18).  
251
+                Console::TableRowCell($standalone, 15, Console::ALIGN_CENTER)  
253 252
             );
254 253
         }
255 254
         //Console::log(Console::tableRowSeparator($rowHeaders), 'darkgray');
@@ -268,11 +267,11 @@  discard block
 block discarded – undo
268 267
      */
269 268
     protected static function reportIP(array $arguments): void
270 269
     {
271
-        $ip      = self::getArgumentValue($arguments,'R', 'report');
272
-        $cats    = self::getArgumentValue($arguments,'c', 'categories');
273
-        $message = self::getArgumentValue($arguments,'m', 'message');
270
+        $ip      = self::getArgumentValue($arguments, 'R', 'report');
271
+        $cats    = self::getArgumentValue($arguments, 'c', 'categories');
272
+        $message = self::getArgumentValue($arguments, 'm', 'message');
274 273
         
275
-        self::printTitle(Console::text('  ► Report IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white'));
274
+        self::printTitle(Console::text('  ► Report IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white'));
276 275
         self::printTempMessage();
277 276
 
278 277
         // Peforms request 
@@ -283,7 +282,7 @@  discard block
 block discarded – undo
283 282
         self::clearTempMessage();
284 283
         
285 284
         // check for errors / empty response
286
-        if (self::hasErrors($report)){
285
+        if (self::hasErrors($report)) {
287 286
             self::printFooter();
288 287
             Program::exit(1);
289 288
         }
@@ -292,14 +291,14 @@  discard block
 block discarded – undo
292 291
         $score = empty($report->data->abuseConfidenceScore) ? 0 : $report->data->abuseConfidenceScore;
293 292
         $scoreColor = self::getScoreColor($score);
294 293
 
295
-        switch (self::$outputFormat){
294
+        switch (self::$outputFormat) {
296 295
             case self::OUTPUT_JSON:
297 296
                 echo json_encode($report, JSON_PRETTY_PRINT);
298 297
                 break;
299 298
        
300 299
             case self::OUTPUT_DEFAULT:  
301 300
                 Console::log(
302
-                    Console::text('   ✓', 'green').Console::text(' IP: [', 'white') .
301
+                    Console::text('   ✓', 'green').Console::text(' IP: [', 'white').
303 302
                     Console::text($ip, $scoreColor).Console::text('] successfully reported', 'white')
304 303
                 );
305 304
                 Console::log(Console::text('     Confidence score: ', 'white').self::getScoreBadge($score));
@@ -325,26 +324,26 @@  discard block
 block discarded – undo
325 324
      */
326 325
     protected static function bulkReport(array $arguments): void
327 326
     {
328
-        $fileName = self::getArgumentValue($arguments,'V', 'bulk-report');
327
+        $fileName = self::getArgumentValue($arguments, 'V', 'bulk-report');
329 328
 
330
-        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray') . Console::text(escapeshellcmd($fileName), 'white'));
329
+        self::printTitle(Console::text('  ► Bulk report for file: ', 'darkgray').Console::text(escapeshellcmd($fileName), 'white'));
331 330
         self::printTempMessage();
332 331
 
333 332
         // Peforms request 
334 333
         $timeStart = microtime(true);  
335 334
         $response = self::$api->bulkReport($fileName)->getObject();     
336 335
         $timeEnd = microtime(true);      
337
-        $time = $timeEnd - $timeStart;  // request time
336
+        $time = $timeEnd - $timeStart; // request time
338 337
         self::clearTempMessage();
339 338
 
340 339
         // check for errors / empty response
341
-        if (self::hasErrors($response)){
340
+        if (self::hasErrors($response)) {
342 341
             self::printFooter();
343 342
             Program::exit(1);
344 343
         }
345 344
 
346 345
         // ✓ Done
347
-        switch (self::$outputFormat){
346
+        switch (self::$outputFormat) {
348 347
             case self::OUTPUT_JSON:
349 348
                 echo json_encode($response, JSON_PRETTY_PRINT);
350 349
                 break;
@@ -359,7 +358,7 @@  discard block
 block discarded – undo
359 358
 
360 359
             case self::OUTPUT_PLAINTEXT:
361 360
                 $nbSavedReports = isset($response->data->savedReports) ? $response->data->savedReports : 0;
362
-                echo $nbSavedReports . PHP_EOL;
361
+                echo $nbSavedReports.PHP_EOL;
363 362
                 break;
364 363
 
365 364
         }
@@ -376,8 +375,8 @@  discard block
 block discarded – undo
376 375
      */
377 376
     protected static function clearIP(array $arguments): void
378 377
     {
379
-        $ip = self::getArgumentValue($arguments,'E', 'clear');
380
-        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white'));
378
+        $ip = self::getArgumentValue($arguments, 'E', 'clear');
379
+        self::printTitle(Console::text('  ► Clear reports for IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white'));
381 380
 
382 381
         // Peforms request 
383 382
         self::printTempMessage();
@@ -388,22 +387,22 @@  discard block
 block discarded – undo
388 387
         self::clearTempMessage();
389 388
 
390 389
         // check for errors / empty response
391
-        if (self::hasErrors($response)){
390
+        if (self::hasErrors($response)) {
392 391
             self::printFooter($time);
393 392
             Program::exit(1);
394 393
         }
395 394
         
396 395
         // ✓ Done: print deleted report number 
397
-        switch (self::$outputFormat){
396
+        switch (self::$outputFormat) {
398 397
             case self::OUTPUT_JSON:
399 398
                 echo json_encode($response, JSON_PRETTY_PRINT);
400 399
                 break;
401 400
        
402 401
             case self::OUTPUT_DEFAULT:  
403 402
                 Console::log(
404
-                    Console::text('   ✓', 'green') . 
405
-                    Console::text(' Successfull clear request for IP: [', 'white') .
406
-                    Console::text($ip, 'lightyellow') .
403
+                    Console::text('   ✓', 'green'). 
404
+                    Console::text(' Successfull clear request for IP: [', 'white').
405
+                    Console::text($ip, 'lightyellow').
407 406
                     Console::text(']', 'white')
408 407
                 );
409 408
                 self::printResult('     Deleted reports: ', $response->data->numReportsDeleted ?? 0, 'lightyellow');
@@ -412,7 +411,7 @@  discard block
 block discarded – undo
412 411
                 break;
413 412
 
414 413
             case self::OUTPUT_PLAINTEXT:
415
-                echo ($response->data->numReportsDeleted ?? 0) . PHP_EOL;
414
+                echo ($response->data->numReportsDeleted ?? 0).PHP_EOL;
416 415
                 break;
417 416
 
418 417
         }
@@ -432,8 +431,8 @@  discard block
 block discarded – undo
432 431
         self::printTitle(Console::text('  ► Get Blacklist ', 'darkgray'));
433 432
 
434 433
         $plainText  = (self::$outputFormat === self::OUTPUT_PLAINTEXT); 
435
-        $limit      = self::getNumericParameter($arguments,'l', 'limit', 1000);
436
-        $scoreMin   = self::getNumericParameter($arguments,'s', 'score', 100);
434
+        $limit      = self::getNumericParameter($arguments, 'l', 'limit', 1000);
435
+        $scoreMin   = self::getNumericParameter($arguments, 's', 'score', 100);
437 436
         
438 437
         self::printTempMessage();
439 438
         
@@ -448,13 +447,13 @@  discard block
 block discarded – undo
448 447
         // response could be json on error, while plaintext flag is set
449 448
         $decodedResponse = $response->getObject();
450 449
 
451
-        if (self::hasErrors($decodedResponse, false)){
450
+        if (self::hasErrors($decodedResponse, false)) {
452 451
             self::printFooter($time);
453 452
             Program::exit(1);
454 453
         }
455 454
 
456 455
         // ✓ Done: print deleted report number 
457
-        switch (self::$outputFormat){
456
+        switch (self::$outputFormat) {
458 457
             case self::OUTPUT_JSON:
459 458
                 echo json_encode($decodedResponse, JSON_PRETTY_PRINT);
460 459
                 break;
@@ -463,7 +462,7 @@  discard block
 block discarded – undo
463 462
                  // print list
464 463
                 self::printResult('  List generated at: ', self::getDate($decodedResponse->meta->generatedAt), 'lightyellow', '');
465 464
                 Console::log();
466
-                foreach ($decodedResponse->data as $report){
465
+                foreach ($decodedResponse->data as $report) {
467 466
                     $score = empty($report->abuseConfidenceScore) ? 0 : $report->abuseConfidenceScore;
468 467
                     $defaultColor = self::getScoreColor($score);
469 468
 
@@ -498,12 +497,12 @@  discard block
 block discarded – undo
498 497
      */
499 498
     protected static function checkBlock(array $arguments): void
500 499
     {
501
-        $network  = self::getArgumentValue($arguments,'K', 'check-block');
500
+        $network = self::getArgumentValue($arguments, 'K', 'check-block');
502 501
 
503
-        self::printTitle(Console::text('  ► Check network: ', 'darkgray') . Console::text(escapeshellcmd($network), 'white') . Console::text('', 'darkgray'));
502
+        self::printTitle(Console::text('  ► Check network: ', 'darkgray').Console::text(escapeshellcmd($network), 'white').Console::text('', 'darkgray'));
504 503
 
505 504
         $maxAge   = self::getNumericParameter($arguments, 'd', 'days', 30);
506
-        $limit    = self::getNumericParameter($arguments,'l', 'limit', 0); // 0 mean no limit
505
+        $limit    = self::getNumericParameter($arguments, 'l', 'limit', 0); // 0 mean no limit
507 506
 
508 507
         self::printTempMessage();
509 508
 
@@ -514,19 +513,19 @@  discard block
 block discarded – undo
514 513
         self::clearTempMessage();
515 514
 
516 515
         // check for errors / empty response
517
-        if (self::hasErrors($check)){
516
+        if (self::hasErrors($check)) {
518 517
             self::printFooter($time);
519 518
             Program::exit(1);
520 519
         }
521 520
 
522
-        switch (self::$outputFormat){
521
+        switch (self::$outputFormat) {
523 522
             case self::OUTPUT_JSON:
524 523
                 echo json_encode($check, JSON_PRETTY_PRINT);
525 524
                 break;
526 525
        
527 526
             case self::OUTPUT_DEFAULT:  
528 527
                 self::printCheckBlockDetail($check);
529
-                self::printCheckBlockReportedIP($check,$maxAge,$limit);
528
+                self::printCheckBlockReportedIP($check, $maxAge, $limit);
530 529
                 Console::log();
531 530
                 self::printFooter($time);
532 531
                 break;
@@ -535,8 +534,8 @@  discard block
 block discarded – undo
535 534
                 $nbReports = isset($check->data->reportedAddress) ? count($check->data->reportedAddress) : 0;
536 535
                 if ($nbReports > 0) {
537 536
                     $numberDiplayedReports = 0;
538
-                    foreach ($check->data->reportedAddress as $report){
539
-                        echo ($report->ipAddress) . ' ' . $report->abuseConfidenceScore . PHP_EOL;
537
+                    foreach ($check->data->reportedAddress as $report) {
538
+                        echo ($report->ipAddress).' '.$report->abuseConfidenceScore.PHP_EOL;
540 539
 
541 540
                         // counter
542 541
                         $numberDiplayedReports++;
@@ -560,14 +559,14 @@  discard block
 block discarded – undo
560 559
      */
561 560
     protected static function checkIP(array $arguments): void
562 561
     {
563
-        $ip = self::getArgumentValue($arguments,'C', 'check');
562
+        $ip = self::getArgumentValue($arguments, 'C', 'check');
564 563
         
565
-        self::printTitle(Console::text('  ► Check IP: ', 'darkgray') . Console::text(escapeshellcmd($ip), 'white') . Console::text('', 'darkgray'));
564
+        self::printTitle(Console::text('  ► Check IP: ', 'darkgray').Console::text(escapeshellcmd($ip), 'white').Console::text('', 'darkgray'));
566 565
         
567
-        $verbose            = self::inArguments($arguments,'v', 'verbose');
566
+        $verbose            = self::inArguments($arguments, 'v', 'verbose');
568 567
         $maxAge             = self::getNumericParameter($arguments, 'd', 'days', 30);
569
-        $maxReportsNumber   = self::getNumericParameter($arguments,'l', 'limit', 10);
570
-        $ip                 = self::getArgumentValue($arguments,'C', 'check');
568
+        $maxReportsNumber   = self::getNumericParameter($arguments, 'l', 'limit', 10);
569
+        $ip                 = self::getArgumentValue($arguments, 'C', 'check');
571 570
 
572 571
         self::printTempMessage();
573 572
         $timeStart = microtime(true);                                           
@@ -577,7 +576,7 @@  discard block
 block discarded – undo
577 576
         self::clearTempMessage();
578 577
 
579 578
         // check for errors / empty response
580
-        if (self::hasErrors($check)){
579
+        if (self::hasErrors($check)) {
581 580
             self::printFooter($time);
582 581
             Program::exit(1);
583 582
         }
@@ -585,7 +584,7 @@  discard block
 block discarded – undo
585 584
         // score and data color (depending of abuseConfidenceScore)
586 585
         $score = empty($check->data->abuseConfidenceScore) ? 0 : $check->data->abuseConfidenceScore;
587 586
 
588
-        switch (self::$outputFormat){
587
+        switch (self::$outputFormat) {
589 588
             case self::OUTPUT_JSON:
590 589
                 echo json_encode($check, JSON_PRETTY_PRINT);
591 590
                 break;
@@ -595,7 +594,7 @@  discard block
 block discarded – undo
595 594
                 self::printCheckScore($check);
596 595
                 self::printCheckDetail($check, $defaultColor);
597 596
                 self::printCheckReports($check, $maxAge, $defaultColor);
598
-                if ($verbose){
597
+                if ($verbose) {
599 598
                     self::printCheckLastReports($check, $maxReportsNumber);
600 599
                 }
601 600
                 Console::log();
@@ -603,7 +602,7 @@  discard block
 block discarded – undo
603 602
                 break;
604 603
 
605 604
             case self::OUTPUT_PLAINTEXT:
606
-                echo ($check->data->abuseConfidenceScore ?? 0) . PHP_EOL;
605
+                echo ($check->data->abuseConfidenceScore ?? 0).PHP_EOL;
607 606
                 break;
608 607
 
609 608
         }
Please login to merge, or discard this patch.
src/AbstractClient.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         $given = self::getArgumentValue($arguments, 'o', 'output') ?? 'default';
119 119
         $output = empty($given) ? 'default' : $given; 
120 120
         self::validate(in_array($output, ['default', 'json', 'plaintext']), 'Invalid output argument given.');
121
-        self::$outputFormat = $output ;
121
+        self::$outputFormat = $output;
122 122
     }
123 123
 
124 124
     /**
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
     protected static function createHandler(): void
135 135
     {
136 136
         try {
137
-            $mainConfPath  = self::$configPath . DIRECTORY_SEPARATOR . 'conf.ini';
138
-            $localConfPath = self::$configPath . DIRECTORY_SEPARATOR . 'local.ini';
137
+            $mainConfPath  = self::$configPath.DIRECTORY_SEPARATOR.'conf.ini';
138
+            $localConfPath = self::$configPath.DIRECTORY_SEPARATOR.'local.ini';
139 139
 
140 140
             // Check main file exists and is readable
141 141
             // Even if a local file exists, main file must be here (throws ex otherwise)
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
             $selfIps = self::extractSelfIpsFromConf($mainConfigArray, $localConfigArray);
146 146
             $apiKey  = self::extractApiKeyFromConf($mainConfigArray, $localConfigArray);
147 147
             
148
-            self::$api =  new QuietApiHandler($apiKey, $selfIps);
148
+            self::$api = new QuietApiHandler($apiKey, $selfIps);
149 149
         } catch (\Exception $e) {
150 150
             self::error($e->getMessage());
151 151
             self::printFooter();
@@ -165,10 +165,10 @@  discard block
 block discarded – undo
165 165
      */
166 166
     protected static function extractSelfIpsFromConf(array $conf, array $localConf): array
167 167
     {
168
-        if (array_key_exists('self_ips', $localConf)){
168
+        if (array_key_exists('self_ips', $localConf)) {
169 169
             return array_map('trim', explode(',', $localConf['self_ips']));
170 170
         }
171
-        if (array_key_exists('self_ips', $conf)){
171
+        if (array_key_exists('self_ips', $conf)) {
172 172
             return array_map('trim', explode(',', $conf['self_ips']));
173 173
         }
174 174
         return [];
@@ -187,15 +187,15 @@  discard block
 block discarded – undo
187 187
     {
188 188
         $key = '';
189 189
 
190
-        if (array_key_exists('api_key', $localConf)){
190
+        if (array_key_exists('api_key', $localConf)) {
191 191
             $key = $localConf['api_key'];
192 192
         }
193 193
         
194
-        if (empty($key) && array_key_exists('api_key', $conf)){
194
+        if (empty($key) && array_key_exists('api_key', $conf)) {
195 195
             $key = $conf['api_key'];
196 196
         }
197 197
 
198
-        if (empty($key)){
198
+        if (empty($key)) {
199 199
             throw new \RuntimeException('Api key is missing.');
200 200
         }
201 201
 
@@ -215,21 +215,21 @@  discard block
 block discarded – undo
215 215
      */
216 216
     protected static function loadConfigFile(string $path, bool $mandatory = false): array
217 217
     {
218
-        if (file_exists($path) && is_file($path)){
218
+        if (file_exists($path) && is_file($path)) {
219 219
 
220 220
             // If main file or a local file is not readable then throws ex.
221
-            if (!is_readable($path)){
221
+            if (!is_readable($path)) {
222 222
                 throw new \RuntimeException('The configuration file ['.$path.'] is not readable.');
223 223
             }
224 224
 
225
-            $conf = parse_ini_file($path, false);  // load without sections...
226
-            if ($conf === false){
225
+            $conf = parse_ini_file($path, false); // load without sections...
226
+            if ($conf === false) {
227 227
                 throw new \RuntimeException('Unable to read configuration file ['.$path.'].');
228 228
             }
229 229
             return $conf;
230 230
         }
231 231
 
232
-        if ($mandatory){
232
+        if ($mandatory) {
233 233
             throw new \RuntimeException('The configuration file ['.$path.'] does not exist.');
234 234
         }
235 235
         return [];
Please login to merge, or discard this patch.