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.
Passed
Push — master ( cbefb9...572e24 )
by Choraimy
07:31
created

ShorteStShortener::shortenAsync()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
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 Psr\Http\Message\ResponseInterface;
8
use function GuzzleHttp\json_decode;
9
10
class ShorteStShortener extends RemoteShortener
11
{
12
    protected $client;
13
    protected $defaults;
14
15
    /**
16
     * Create a new Shorte.st shortener.
17
     *
18
     * @param \GuzzleHttp\ClientInterface $client
19
     * @param string $token
20
     * @return void
21
     */
22 34
    public function __construct(ClientInterface $client, string $token)
23
    {
24 34
        $this->client = $client;
25 34
        $this->defaults = [
26 34
            'allow_redirects' => false,
27 34
            'base_uri' => 'https://api.shorte.st',
28
            'headers' => [
29 34
                'Accept' => 'application/json',
30 34
                'Public-API-Token' => $token,
31 34
                'Content-Type' => 'application/x-www-form-urlencoded',
32
            ],
33
        ];
34 34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 34
    public function shortenAsync($url, array $options = [])
40
    {
41 34
        $options = array_merge($this->defaults, $options);
42 34
        $request = new Request('PUT', '/v1/data/url', [], http_build_query(['urlToShorten' => $url]));
43
44 30
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
45 34
            return json_decode($response->getBody()->getContents())->shortenedUrl;
46 34
        });
47
    }
48
}
49