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   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 46
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A shortenAsync() 0 7 1
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