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 (#38)
by Choraimy
08:26
created

TinyUrl   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A toPromise() 0 7 1
1
<?php
2
3
namespace LaraCrafts\UrlShortener\Http;
4
5
use GuzzleHttp\ClientInterface;
6
use GuzzleHttp\Promise\PromiseInterface;
7
use GuzzleHttp\Psr7\Request;
8
use Illuminate\Support\Arr;
9
use LaraCrafts\UrlShortener\Concerns\ToPromise;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\UriInterface;
12
13
class TinyUrl implements ToPromise
14
{
15
    protected $client;
16
    protected $defaults;
17
18
    /**
19
     * Create a new TinyURL shortener.
20
     *
21
     * @param \GuzzleHttp\ClientInterface $client
22
     * @return void
23
     */
24
    public function __construct(ClientInterface $client)
25
    {
26
        $this->client = $client;
27
        $this->defaults = [
28
            'allow_redirects' => false,
29
            'base_uri' => 'https://tinyurl.com',
30
        ];
31
    }
32
33
    /**
34
     * {@inheritDoc}
35
     */
36
    public function toPromise(UriInterface $uri, array $options): PromiseInterface
37
    {
38
        $options = array_merge_recursive(Arr::add($this->defaults, 'query.url', (string)$uri), $options);
39
        $request = new Request('POST', '/api-create.php');
40
41
        return $this->client->sendAsync($request, $options)->then(function (ResponseInterface $response) {
42
            return str_replace('http://', 'https://', $response->getBody()->getContents());
43
        });
44
    }
45
}
46