Auth::request()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace Audiens\DoubleclickClient;
4
5
use Audiens\DoubleclickClient\authentication\AuthStrategyInterface;
6
use Doctrine\Common\Cache\Cache;
7
use GuzzleHttp\Client;
8
use GuzzleHttp\ClientInterface;
9
10
/**
11
 * Class Auth
12
 */
13
class Auth extends Client implements ClientInterface
14
{
15
16
    /**
17
 * @var  Cache
18
*/
19
    protected $cache;
20
21
    /**
22
 * @var  Client
23
*/
24
    protected $client;
25
26
    /**
27
 * @var string
28
*/
29
    protected $token;
30
31
    /**
32
 * @var AuthStrategyInterface
33
*/
34
    protected $authStrategy;
35
36
    /**
37
     * Auth constructor.
38
     *
39
     * @param ClientInterface       $clientInterface
40
     * @param AuthStrategyInterface $authStrategy
41
     */
42
    public function __construct(ClientInterface $clientInterface, AuthStrategyInterface $authStrategy)
43
    {
44
        $this->client = $clientInterface;
0 ignored issues
show
Documentation Bug introduced by
$clientInterface is of type object<GuzzleHttp\ClientInterface>, but the property $client was declared to be of type object<GuzzleHttp\Client>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
45
        $this->authStrategy = $authStrategy;
46
47
        parent::__construct([]);
48
    }
49
50
    /**
51
     * @param string $method
52
     * @param null   $uri
53
     * @param array  $options
54
     *
55
     * @return mixed|\Psr\Http\Message\ResponseInterface
56
     * @throws \Exception
57
     */
58
    public function request($method, $uri = null, array $options = [])
59
    {
60
61
        $optionForToken = [
62
            'headers' => [
63
                'Authorization' => (string)$this->authStrategy->authenticate(),
64
            ],
65
        ];
66
67
        $options = array_merge($options, $optionForToken);
68
69
        return $this->client->request($method, $uri, $options);
70
    }
71
}
72