Passed
Push — master ( 542807...000b7f )
by Hector Luis
11:24
created

Token::setParams()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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

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

60
            /** @scrutinizer ignore-call */ 
61
            $response = $this->connector->request($this->verb, $endPoint, $headers, $params);
Loading history...
61
            $this->accessToken = $response->content;
0 ignored issues
show
Bug introduced by
Accessing content on the interface Ticaje\Contract\Patterns...onder\ResponseInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
62
        }
63
        return $this->accessToken;
64
    }
65
66
    /**
67
     * @inheritDoc
68
     * Perhaps using composition on this might be a cleaner way
69
     */
70
    public function setParams(array $params): CredentialInterface
71
    {
72
        $this->params = $params;
73
        return $this;
74
    }
75
}
76