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(); |
|
|
|
|
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(); |
|
|
|
|
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
|
|
|
|
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.