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.

FirebaseShortener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 48
ccs 13
cts 13
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A shortenAsync() 0 7 1
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 FirebaseShortener extends RemoteShortener
12
{
13
    protected $client;
14
    protected $defaults;
15
16
    /**
17
     * Create a new Firebase shortener.
18
     *
19
     * @param \GuzzleHttp\ClientInterface $client
20
     * @param string $token
21
     * @param string $domain
22
     * @param string $suffix
23
     * @return void
24
     */
25 60
    public function __construct(ClientInterface $client, string $token, string $domain, string $suffix)
26
    {
27 60
        $this->client = $client;
28 60
        $this->defaults = [
29 60
            'allow_redirects' => false,
30 60
            'base_uri' => 'https://firebasedynamiclinks.googleapis.com',
31
            'headers' => [
32
                'Content-Type' => 'application/json',
33
                'Accept' => 'application/json',
34
            ],
35
            'query' => [
36 60
                'key' => $token,
37
            ],
38
            'json' => [
39
                'dynamicLinkInfo' => [
40 60
                    'domainUriPrefix' => $domain,
41
                ],
42
                'suffix' => [
43 60
                    "option" => $suffix,
44
                ],
45
            ],
46
        ];
47 60
    }
48
49
    /**
50
     * {@inheritDoc}
51
     */
52 60
    public function shortenAsync($url, array $options = [])
53
    {
54 60
        $options = array_merge_recursive(Arr::add($this->defaults, 'json.dynamicLinkInfo.link', $url), $options);
55 60
        $request = new Request('POST', '/v1/shortLinks');
56
57
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
58 50
            return json_decode($response->getBody()->getContents())->shortLink;
59 60
        });
60
    }
61
}
62