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.

TinyUrlShortener   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 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
10
class TinyUrlShortener extends RemoteShortener
11
{
12
    protected $client;
13
    protected const defaults = [
14
        'allow_redirects' => false,
15
        'base_uri' => 'https://tinyurl.com',
16
    ];
17
18
    /**
19
     * Create a new TinyURL shortener.
20
     *
21
     * @param \GuzzleHttp\ClientInterface $client
22
     * @return void
23
     */
24 40
    public function __construct(ClientInterface $client)
25
    {
26 40
        $this->client = $client;
27 40
    }
28
29
    /**
30
     * {@inheritDoc}
31
     */
32 40
    public function shortenAsync($url, array $options = [])
33
    {
34 40
        $options = array_merge(Arr::add(static::defaults, 'query.url', $url), $options);
35 40
        $request = new Request('GET', '/api-create.php');
36
37
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
38 30
            return str_replace('http://', 'https://', $response->getBody()->getContents());
39 40
        });
40
    }
41
}
42