Token::getAccessToken()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 14
rs 9.9666
cc 2
nc 2
nop 0
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Gateway Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AConnector\Gateway\Provider\Token;
11
12
use Ticaje\Contract\Patterns\Interfaces\Decorator\Responder\ResponseInterface;
13
14
use Ticaje\AConnector\Gateway\Provider\Base;
15
use Ticaje\AConnector\Interfaces\ClientInterface;
16
use Ticaje\AConnector\Interfaces\Provider\Token\TokenProviderInterface;
17
18
/**
19
 * Class Token
20
 * @package Ticaje\AConnector\Gateway\Provider\Token
21
 */
22
class Token extends Base implements TokenProviderInterface
23
{
24
    protected $accessToken;
25
26
    protected $verb;
27
28
    protected $endpoint;
29
30
    protected $baseUri;
31
32
    /**
33
     * Token constructor.
34
     * @param ClientInterface $connector
35
     * @param string $endpoint
36
     * @param string $verb
37
     * @param string $baseUri
38
     */
39
    public function __construct(
40
        ClientInterface $connector,
41
        string $endpoint,
42
        string $verb,
43
        string $baseUri
44
    ) {
45
        $this->verb = $verb;
46
        $this->endpoint = $endpoint;
47
        $this->baseUri = $baseUri;
48
        parent::__construct($connector);
49
        $this->initialize([ClientInterface::BASE_URI_KEY => $this->baseUri]);
50
    }
51
52
    /**
53
     * @inheritDoc
54
     */
55
    public function getAccessToken()
56
    {
57
        if (!$this->accessToken) {
58
            $headers = [
59
                ClientInterface::CONTENT_TYPE_KEY => ClientInterface::CONTENT_TYPE_FORM_URLENCODED,
60
                'Accept' => ClientInterface::CONTENT_TYPE_JSON,
61
            ];
62
            $params = $this->params;
63
            $endPoint = $this->endpoint;
64
            /** @var ResponseInterface $response */
65
            $response = $this->connector->request($this->verb, $endPoint, $headers, $params);
0 ignored issues
show
Bug introduced by
The method request() does not exist on Ticaje\AConnector\Interfaces\ClientInterface. It seems like you code against a sub-type of Ticaje\AConnector\Interfaces\ClientInterface such as Ticaje\AConnector\Interf...col\RestClientInterface or Ticaje\AConnector\Interf...col\SoapClientInterface or Ticaje\AConnector\Gatewa...ations\Client\Rest\Curl or Ticaje\AConnector\Gatewa...ions\Client\Rest\Guzzle or Ticaje\AConnector\Gateway\Client\Rest or Ticaje\AConnector\Gateway\Client\Soap. ( Ignorable by Annotation )

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

65
            /** @scrutinizer ignore-call */ 
66
            $response = $this->connector->request($this->verb, $endPoint, $headers, $params);
Loading history...
66
            $this->accessToken = $response; // Gonna return the response in raw since there must be a responder module interpreting the response in a per business domain basis.
67
        }
68
        return $this->accessToken;
69
    }
70
71
    /**
72
     * @inheritDoc
73
     * Perhaps using composition on this might be a cleaner way
74
     */
75
    public function setParams(array $params): TokenProviderInterface
76
    {
77
        $this->params = $params;
78
        return $this;
79
    }
80
}
81