ListAppAuth::handle()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 27
rs 9.3888
cc 5
nc 4
nop 0
1
<?php
2
3
namespace ArcherZdip\LaravelApiAuth\Console\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
use ArcherZdip\LaravelApiAuth\Models\AppClient;
7
8
class ListAppAuth extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'apikey:list {--D|deleted}';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = "List all AppId and Secret";
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
        $lists = $this->option('deleted')
42
            ? AppClient::withTrashed()->orderBy('name')->get()
43
            : AppClient::orderBy('name')->get();
44
45
        if ($lists->count() === 0) {
46
            $this->info('There are no APPID');
47
            exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
48
        }
49
50
        $headers = ['AppName', 'AppId', 'Secret', 'Status', 'CreateAt'];
51
52
        $rows = $lists->map(function ($list) {
53
            $status = $list->active ? 'active' : 'deactivated';
54
            $status = $list->trashed() ? 'deleted' : $status;
55
56
            return [
57
                $list->name,
58
                $list->appid,
59
                $list->secret,
60
                $status,
61
                $list->created_at
62
            ];
63
        });
64
65
        $this->table($headers, $rows);
66
    }
67
}
68