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.

BitLyShortener::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

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