Completed
Push — master ( 119d8b...4441ec )
by Chris
20s
created

ListTokens::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Yab\FlightDeck\Commands;
4
5
use Illuminate\Console\Command;
6
use Illuminate\Support\Facades\DB;
7
8
class ListTokens extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'flightdeck:list';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'List all available API tokens';
23
24
    /**
25
     * Execute the console command.
26
     *
27
     * @return mixed
28
     */
29
    public function handle()
30
    {
31
        $tokens = DB::table('api_tokens')->get();
32
        if ($tokens->count() === 0) {
33
            $this->info('There are no API keys');
34
            return;
35
        }
36
37
        $headers = ['Name', 'Token', 'Expires At'];
38
        $rows = $tokens->map(function ($token) {
39
            return [
40
                $token->name,
41
                $token->token,
42
                $token->expires_at,
43
            ];
44
        });
45
        $this->table($headers, $rows);
46
    }
47
}
48