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.
Completed
Push — master ( df7c21...8540f8 )
by
unknown
09:53
created

PolrShortener::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 3
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 1
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
namespace LaraCrafts\UrlShortener\Http;
4
5
use GuzzleHttp\ClientInterface;
6
use GuzzleHttp\Psr7\Request;
7
use Illuminate\Support\Arr;
8
use Psr\Http\Message\ResponseInterface;
9
use function GuzzleHttp\json_decode;
10
11
class PolrShortener extends RemoteShortener
12
{
13
    /**
14
     * @var \GuzzleHttp\ClientInterface
15
     */
16
    protected $client;
17
18
    /**
19
     * @var array
20
     */
21
    protected $defaults;
22
23
    /**
24
     * Create a new Polr shortener.
25
     *
26
     * @param \GuzzleHttp\ClientInterface $client
27
     * @param string $token
28
     * @param string $domain
29
     * @return void
30
     */
31 72
    public function __construct(ClientInterface $client, string $token, string $domain)
32
    {
33 72
        $this->client = $client;
34 72
        $this->defaults = [
35 72
            'allow_redirects' => false,
36 72
            'base_uri' => $domain,
37
            'headers' => [
38
                'Content-Type' => 'application/json',
39
                'Accept' => 'application/json',
40
            ],
41
            'query' => [
42 72
                'key' => $token,
43
            ],
44
        ];
45 72
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50 48
    public function shortenAsync($url, array $options = [])
51
    {
52 48
        $options = array_merge(Arr::add($this->defaults, 'query.url', $url), $options);
53 48
        $request = new Request('GET', '/api/v2/action/shorten');
54
55 30
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
56 48
            return json_decode($response->getBody()->getContents())->result;
57 48
        });
58
    }
59
}
60