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
Pull Request — master (#26)
by Choraimy
09:30
created

IsGdShortener   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 47
ccs 8
cts 16
cp 0.5
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shortenAsync() 0 7 1
A __construct() 0 9 1
A shortenToAsync() 0 3 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 LaraCrafts\UrlShortener\Contracts\CustomUrls;
9
use Psr\Http\Message\ResponseInterface;
10
11
class IsGdShortener extends RemoteShortener implements CustomUrls
12
{
13
    use Concerns\CreatesCustomUrls;
14
15
    protected $client;
16
    protected $defaults;
17
18
    /**
19
     * Create a new Is.gd shortener.
20
     *
21
     * @param \GuzzleHttp\ClientInterface $client
22
     * @param \Psr\Http\Message\UriInterface|string $baseUri
23
     * @param bool $statistics
24
     * @return void
25
     */
26 48
    public function __construct(ClientInterface $client, $baseUri, bool $statistics)
27
    {
28 48
        $this->client = $client;
29 48
        $this->defaults = [
30 48
            'allow_redirects' => false,
31 48
            'base_uri' => (string)$baseUri,
32
            'query' => [
33 48
                'format' => 'simple',
34 48
                'logstats' => intval($statistics),
35
            ],
36
        ];
37 48
    }
38
39
    /**
40
     * {@inheritDoc}
41
     */
42
    public function shortenAsync($url, array $options = [])
43
    {
44
        $options = Arr::add(array_merge_recursive($this->defaults, $options), 'query.url', $url);
45
        $request = new Request('GET', '/create.php');
46
47
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
48
            return $response->getBody()->getContents();
49
        });
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55
    public function shortenToAsync($url, string $identifier, array $options = [])
56
    {
57
        return $this->shortenAsync($url, Arr::add($options, 'query.shorturl', $identifier));
58
    }
59
}
60