Passed
Push — master ( c43702...75ec29 )
by Radu
02:13
created

Command   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 42
c 2
b 0
f 0
dl 0
loc 72
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A current() 0 10 1
A validateAuthenticationToken() 0 24 2
A generateAuthenticationToken() 0 13 1
A __construct() 0 12 1
1
<?php
2
namespace ParcelValue\ApiClient\Domain\Clients;
3
4
use ParcelValue\Api\AuthenticationToken;
5
6
use WebServCo\Framework\Cli\Ansi;
7
use WebServCo\Framework\Cli\Response;
8
use WebServCo\Framework\Cli\Sgr;
9
use WebServCo\Framework\Http\Method;
10
11
final class Command extends \ParcelValue\ApiClient\AbstractController
12
{
13
    protected $jwt;
14
15
    use \ParcelValue\ApiClient\Traits\ControllerApiTrait;
16
17
    public function __construct()
18
    {
19
        parent::__construct();
20
21
        $this->repository = new Repository($this->outputLoader);
22
23
        $this->validateApiConfig();
24
25
        $this->jwt = \ParcelValue\Api\AuthenticationToken::generate(
26
            $this->clientId,
27
            $this->clientKey,
28
            $this->serverKey
29
        );
30
    }
31
32
    public function current()
33
    {
34
        $this->outputCli(Ansi::clear(), true);
35
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
36
37
        $url = sprintf('%s%s/clients/current', $this->apiUrl, $this->apiVersion);
38
39
        $this->handleApiCall($this->jwt, $url, Method::GET);
40
41
        return new Response('', true);
42
    }
43
44
    public function generateAuthenticationToken()
45
    {
46
        $this->outputCli(Ansi::clear(), true);
47
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
48
        $this->outputCli();
0 ignored issues
show
Bug introduced by
The call to ParcelValue\ApiClient\Do...ts\Command::outputCli() has too few arguments starting with string. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

48
        $this->/** @scrutinizer ignore-call */ 
49
               outputCli();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
49
50
        $jwt = AuthenticationToken::generate($this->clientId, $this->clientKey, $this->serverKey);
51
        $this->outputCli(Ansi::sgr('Success!', [Sgr::GREEN]), false);
52
        $this->outputCli(' Your token is:', true);
53
        $this->outputCli();
54
        $this->outputCli($jwt, true);
55
        $this->outputCli();
56
        return new \WebServCo\Framework\Cli\Response('', true);
57
    }
58
59
    public function validateAuthenticationToken($token)
60
    {
61
        $this->outputCli(Ansi::clear(), true);
62
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
63
        $this->outputCli();
0 ignored issues
show
Bug introduced by
The call to ParcelValue\ApiClient\Do...ts\Command::outputCli() has too few arguments starting with string. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
        $this->/** @scrutinizer ignore-call */ 
64
               outputCli();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
64
        $this->outputCli(sprintf('Input: %s', $token), true);
65
        $this->outputCli();
66
67
        try {
68
            $result = AuthenticationToken::decode($token, $this->serverKey);
69
            $this->outputCli(Ansi::sgr('Success!', [Sgr::GREEN]), true);
70
            $this->outputCli(var_export($result, true), true);
71
        } catch (\Exception $e) {
72
            $this->outputCli(
73
                Ansi::sgr(
74
                    sprintf('Error: %s', $e->getMessage()),
75
                    [Sgr::RED]
76
                ),
77
                true
78
            );
79
        }
80
81
        $this->outputCli();
82
        return new \WebServCo\Framework\Cli\Response('', true);
83
    }
84
}
85