TokenDecorator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 41
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 6 2
A launchSuccess() 0 6 1
A launchFailed() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Token Provider Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AeSdk\Infrastructure\Provider\Token;
11
12
use Ticaje\AeSdk\Infrastructure\Interfaces\Provider\Token\TokenResponderInterface;
13
use Ticaje\Contract\Patterns\Interfaces\Decorator\Responder\ResponseInterface as ContractResponseInterface;
14
use Ticaje\Contract\Traits\BaseDto;
15
16
/**
17
 * Class TokenDecorator
18
 * @package Ticaje\AeSdk\Infrastructure\Provider\Token
19
 * This is a high level module hence a specific implementation, you can notice specific constraints when it comes to
20
 * handle data coming from AE API.
21
 */
22
class TokenDecorator implements TokenResponderInterface
23
{
24
    use BaseDto;
25
26
    private $success;
0 ignored issues
show
introduced by
The private property $success is not used, and could be removed.
Loading history...
27
28
    private $accessToken;
0 ignored issues
show
introduced by
The private property $accessToken is not used, and could be removed.
Loading history...
29
30
    private $accessTokenValidity;
0 ignored issues
show
introduced by
The private property $accessTokenValidity is not used, and could be removed.
Loading history...
31
32
    private $message;
0 ignored issues
show
introduced by
The private property $message is not used, and could be removed.
Loading history...
33
34
    /**
35
     * @inheritDoc
36
     */
37
    public function process(ContractResponseInterface $response): TokenResponderInterface
38
    {
39
        $content = json_decode($response->getContent());
40
        // This is actually the business policy behind this class
41
        isset($content->access_token) ? $this->launchSuccess($content) : $this->launchFailed($content);
42
        return $this;
43
    }
44
45
    /**
46
     * @param $content
47
     */
48
    private function launchSuccess($content)
49
    {
50
        $this->setSuccess(true);
0 ignored issues
show
Bug introduced by
The method setSuccess() does not exist on Ticaje\AeSdk\Infrastruct...er\Token\TokenDecorator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

50
        $this->/** @scrutinizer ignore-call */ 
51
               setSuccess(true);
Loading history...
51
        $this->setAccessToken($content->access_token);
0 ignored issues
show
Bug introduced by
The method setAccessToken() does not exist on Ticaje\AeSdk\Infrastruct...er\Token\TokenDecorator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

51
        $this->/** @scrutinizer ignore-call */ 
52
               setAccessToken($content->access_token);
Loading history...
52
        $this->setAccessTokenValidity($content->expire_time);
0 ignored issues
show
Bug introduced by
The method setAccessTokenValidity() does not exist on Ticaje\AeSdk\Infrastruct...er\Token\TokenDecorator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

52
        $this->/** @scrutinizer ignore-call */ 
53
               setAccessTokenValidity($content->expire_time);
Loading history...
53
        $this->setMessage("Token generated successfully");
0 ignored issues
show
Bug introduced by
The method setMessage() does not exist on Ticaje\AeSdk\Infrastruct...er\Token\TokenDecorator. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
        $this->/** @scrutinizer ignore-call */ 
54
               setMessage("Token generated successfully");
Loading history...
54
    }
55
56
    /**
57
     * @param $content
58
     */
59
    private function launchFailed($content)
60
    {
61
        $this->setSuccess(false);
62
        $this->setMessage("There was a problem generating token: {$content->error_msg}");
63
    }
64
}
65