Passed
Push — master ( 1a60b5...c43702 )
by Radu
01:33
created

Command::generateAuthenticationToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 0
dl 0
loc 13
rs 9.9332
c 0
b 0
f 0
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\Sgr;
8
9
final class Command extends \ParcelValue\ApiClient\AbstractController
10
{
11
    use \ParcelValue\ApiClient\Traits\ControllerApiTrait;
12
13
    public function __construct()
14
    {
15
        parent::__construct();
16
17
        $this->repository = new Repository($this->outputLoader);
18
19
        $this->validateApiConfig();
20
    }
21
22
    public function generateAuthenticationToken()
23
    {
24
        $this->outputCli(Ansi::clear(), true);
25
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
26
        $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

26
        $this->/** @scrutinizer ignore-call */ 
27
               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...
27
28
        $jwt = AuthenticationToken::generate($this->clientId, $this->clientKey, $this->serverKey);
29
        $this->outputCli(Ansi::sgr('Success!', [Sgr::GREEN]), false);
30
        $this->outputCli(' Your token is:', true);
31
        $this->outputCli();
32
        $this->outputCli($jwt, true);
33
        $this->outputCli();
34
        return new \WebServCo\Framework\Cli\Response('', true);
35
    }
36
37
    public function validateAuthenticationToken($token)
38
    {
39
        $this->outputCli(Ansi::clear(), true);
40
        $this->outputCli(Ansi::sgr(__METHOD__, [Sgr::BOLD]), true);
41
        $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

41
        $this->/** @scrutinizer ignore-call */ 
42
               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...
42
        $this->outputCli(sprintf('Input: %s', $token), true);
43
        $this->outputCli();
44
45
        try {
46
            $result = AuthenticationToken::decode($token, $this->serverKey);
47
            $this->outputCli(Ansi::sgr('Success!', [Sgr::GREEN]), true);
48
            $this->outputCli(var_export($result, true), true);
49
        } catch (\Exception $e) {
50
            $this->outputCli(
51
                Ansi::sgr(
52
                    sprintf('Error: %s', $e->getMessage()),
53
                    [Sgr::RED]
54
                ),
55
                true
56
            );
57
        }
58
59
        $this->outputCli();
60
        return new \WebServCo\Framework\Cli\Response('', true);
61
    }
62
}
63