Passed
Push — master ( 07bc23...954a10 )
by Dominic
02:25
created

AccessTokenCommand::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 7
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 11
rs 10
1
<?php
2
3
namespace tbclla\Revolut\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use tbclla\Revolut\Auth\TokenManager;
7
use tbclla\Revolut\Exceptions\AppUnauthorizedException;
8
9
class AccessTokenCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'revolut:access-token';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Get an active revolut access token.';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle(TokenManager $manager)
31
    {
32
        try {
33
            $accessToken = $manager->getAccessToken();
34
        } catch(AppUnauthorizedException $e) {
35
            $this->error('No valid refresh token found.');
36
            $this->line("calling 'revolut:authorize' to re-authorize...");
37
            return $this->call('revolut:authorize');
38
        }
39
40
        $this->info($accessToken->value);
41
    }
42
}
43