BlackListCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 61
ccs 0
cts 24
cp 0
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 7 1
A formTableHeaders() 0 13 2
1
<?php
2
3
namespace Someshwer\Firewall\Commands;
4
5
use Illuminate\Console\Command;
0 ignored issues
show
Bug introduced by
The type Illuminate\Console\Command was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
/**
8
 * This class displays all the black listed ip addresses on console.
9
 *
10
 * Class BlackListCommand
11
 */
12
class BlackListCommand extends Command
13
{
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'firewall:blacklist';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'This command fetches all ip addresses that are added to blacklist array in "firewall" config file.';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     * This command returns and displays all black listed ip addresses.
41
     *
42
     * @return void
43
     */
44
    public function handle()
45
    {
46
        $black_list = config('firewall.blacklist');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
        $black_list = /** @scrutinizer ignore-call */ config('firewall.blacklist');
Loading history...
47
        $headers = ['SNO', 'IP Address', 'Blacklist'];
48
        $ip_list = $this->formTableHeaders($black_list);
49
        $this->table($headers, $ip_list);
50
        $this->info('Done!!');
51
    }
52
53
    /**
54
     * Decorate values as table with headers.
55
     *
56
     * @param array $black_list
57
     *
58
     * @return array $ip_list
59
     */
60
    private function formTableHeaders($black_list)
61
    {
62
        $ip_list = [];
63
        $i = 1;
64
        foreach ($black_list as $item) {
65
            $ip_list[] = [
66
                'sno'        => $i,
67
                'ip_address' => $item,
68
                'blacklist'  => 'true',
69
            ];
70
        }
71
72
        return $ip_list;
73
    }
74
}
75