AuthorizeCommand::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
nc 2
nop 0
dl 0
loc 14
c 1
b 0
f 0
cc 2
rs 10
1
<?php
2
3
namespace tbclla\Revolut\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use tbclla\Revolut\Auth\Requests\AuthorizationCodeRequest;
7
use tbclla\Revolut\Exceptions\RevolutException;
8
9
class AuthorizeCommand extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'revolut:authorize {--redirect= : A destination to be redirected to after the authorization}';
17
18
    /**
19
     * The console command description.
20
     *
21
     * @var string
22
     */
23
    protected $description = 'Authorize API access for you app';
24
25
    /**
26
     * Execute the console command.
27
     *
28
     * @return mixed
29
     */
30
    public function handle()
31
    {
32
        $redirect = $this->option('redirect') ?? null;
33
34
        if (!$route = config('revolut.auth_route.name')) {
35
            $this->error('Route name invalid or missing');
36
            $this->error('Check you configuration and verify that "auth_route.name" is valid');
37
            return;
38
        }
39
40
        $url = route($route, ['after_success' => $redirect]);
41
42
        $this->info('Follow the link to complete the authorization:');
43
        $this->line('<fg=black;bg=yellow>' . $url . '</>');
44
    }
45
}
46