UnblockIp   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 20 3
1
<?php
2
3
namespace Spinzar\Firewall\Commands;
4
5
use Spinzar\Firewall\Models\Ip;
6
use Carbon\Carbon;
7
use Illuminate\Console\Command;
8
9
class UnblockIp extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'firewall:unblockip';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Unblock ips based on their block period';
24
25
    /**
26
     * Create a new command instance.
27
     */
28
    public function __construct()
29
    {
30
        parent::__construct();
31
    }
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return mixed
37
     */
38
    public function handle()
39
    {
40
        $now = Carbon::now(config('app.timezone'));
41
42
        $ip = config('firewall.models.ip', Ip::class);
43
        $ip::with('log')->blocked()->each(function ($ip) use ($now) {
44
            if (empty($ip->log)) {
45
                return;
46
            }
47
48
            $period = config('firewall.middleware.' . $ip->log->middleware . '.auto_block.period');
49
50
            if ($ip->created_at->addSeconds($period) > $now) {
51
                return;
52
            }
53
54
            $ip->logs()->delete();
55
            $ip->delete();
56
        });
57
    }
58
}
59