PruneBlockListCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 92.86%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 47
ccs 13
cts 14
cp 0.9286
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 26 5
1
<?php
2
3
4
namespace JWTAuth\Console;
5
6
use Illuminate\Console\Command;
7
use Illuminate\Support\Facades\Auth;
8
use InvalidArgumentException;
9
use JWTAuth\Contracts\HasObsoleteRecords;
10
use JWTAuth\JWTGuard;
11
12
/**
13
 * Class PruneBlockListCommand
14
 *
15
 * @example phpartisan jwt:block-list:prune "\JWTAuth\BlockList\FileJwtBlockList"
16
 */
17
class PruneBlockListCommand extends Command
18
{
19
    /**
20
     * The name and signature of the console command.
21
     *
22
     * @var string
23
     */
24
    protected $signature = 'jwt:block-list:prune {guard : Auth guard}';
25
26
    /**
27
     * The console command description.
28
     *
29
     * @var string
30
     */
31
    protected $description = 'Prune blocklist';
32
33
    /**
34
     * Execute the console command.
35
     *
36
     * @return int
37
     */
38 3
    public function handle(): int
39
    {
40 3
        $guardName = $this->argument('guard');
41 3
        if (!is_string($guardName) && !is_null($guardName)) {
42
            throw new InvalidArgumentException('Not valid "guard" parameter.');
43
        }
44
45
        /** @var JWTGuard $guard */
46 3
        $guard     = Auth::guard($guardName);
47 2
        $blockList = $guard->blockList();
48
49 2
        if ($blockList instanceof HasObsoleteRecords) {
50 1
            if ($blockList->removeObsoleteRecords()) {
51 1
                $this->info('Pruned');
52
53 1
                return 0;
54
            }
55
56 1
            $this->error('Prune error');
57
58 1
            return 1;
59
        }
60
61 1
        $this->warn('Blocklist has not interface "HasOutdatedRecords"');
62
63 1
        return 0;
64
    }
65
}
66