GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Client::send()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
1
<?php
2
3
namespace JumpCloud;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use JumpCloud\Provider\CredentialsProviderInterface;
7
use JumpCloud\Handler\RequestHandler;
8
use JumpCloud\Request\RequestInterface;
9
use JumpCloud\Response\ResponseInterface;
10
use Psr\Log\LoggerInterface;
11
use Psr\Log\NullLogger;
12
13
/**
14
 * Class Client
15
 *
16
 * @package JumpCloud
17
 */
18
class Client
19
{
20
    /** @var CredentialsProviderInterface */
21
    private $credentialsProvider;
22
23
    /** @var LoggerInterface */
24
    private $logger;
25
26
    /** @var GuzzleClient */
27
    private $client;
28
29
    /** @var RequestHandler */
30
    private $requesthandler;
31
32
    /**
33
     * Client constructor.
34
     *
35
     * @param CredentialsProviderInterface $credentialsProvider
36
     * @param LoggerInterface|null $logger
37
     * @param GuzzleClient|null $client
38
     */
39 14
    public function __construct(
40
        CredentialsProviderInterface $credentialsProvider,
41
        LoggerInterface $logger = null,
42
        GuzzleClient $client = null
43
    )
44
    {
45 14
        $this->credentialsProvider = $credentialsProvider;
46 14
        $this->logger = $logger ?: new NullLogger();
47
48 14
        $this->client = $client ?: new GuzzleClient(
49
            [
50 2
                'timeout' => 5,
51
                'connection_timeout' => 2,
52
            ]
53
        );
54
55 14
        $this->requesthandler = new RequestHandler($this->logger);
56 14
    }
57
58
    /**
59
     * @param RequestInterface $request
60
     * @return ResponseInterface
61
     */
62 13
    public function send(RequestInterface $request)
63
    {
64 13
        $request->addHeader('x-api-key', $this->credentialsProvider->getKey());
65 13
        $request->addHeader('content-type', 'application/json');
66
67 13
        return $this->requesthandler->handle($this->client, $request);
68
    }
69
}
70