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::toPromise()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 7
ccs 0
cts 5
cp 0
crap 2
rs 10
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