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.
Passed
Push — master ( 572e24...2d9704 )
by Choraimy
07:54
created

UrlShortenerManager::createShorteStDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaraCrafts\UrlShortener;
4
5
use GuzzleHttp\ClientInterface;
6
use Illuminate\Support\Arr;
7
use Illuminate\Support\Manager;
8
use Illuminate\Support\Str;
9
use InvalidArgumentException;
10
use LaraCrafts\UrlShortener\Contracts\Factory;
11
use LaraCrafts\UrlShortener\Http\BitLyShortener;
12
use LaraCrafts\UrlShortener\Http\ShorteStShortener;
13
use LaraCrafts\UrlShortener\Http\TinyUrlShortener;
14
15
/**
16
 * @mixin \LaraCrafts\UrlShortener\Contracts\Shortener
17
 */
18
class UrlShortenerManager extends Manager implements Factory
19
{
20
    /**
21
     * Create an instance of the Bit.ly driver.
22
     *
23
     * @return \LaraCrafts\UrlShortener\Http\BitLyShortener
24
     */
25 29
    protected function createBitLyDriver()
26
    {
27 29
        $config = $this->getDriverConfig('bit_ly');
28
29 29
        return new BitLyShortener(
30 29
            $this->app->make(ClientInterface::class),
31 29
            Arr::get($config, 'token'),
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($config, 'token') can also be of type null; however, parameter $token of LaraCrafts\UrlShortener\...hortener::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            /** @scrutinizer ignore-type */ Arr::get($config, 'token'),
Loading history...
32 29
            Arr::get($config, 'domain', 'bit.ly')
33
        );
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 87
    protected function createDriver($driver)
40
    {
41
        # We overwrite this function with the Laravel 5.8 variant
42
        # because it isn't backwards compatible across supported versions
43
44 87
        if (isset($this->customCreators[$driver])) {
45
            return $this->callCustomCreator($driver);
46
        } else {
47 87
            $method = 'create' . Str::studly($driver) . 'Driver';
48 87
            if (method_exists($this, $method)) {
49 87
                return $this->$method();
50
            }
51
        }
52
53
        throw new InvalidArgumentException("Driver [$driver] not supported.");
54
    }
55
56
    /**
57
     * Create a new instance of the Shorte.st driver.
58
     *
59
     * @return \LaraCrafts\UrlShortener\Http\ShorteStShortener
60
     */
61 29
    protected function createShorteStDriver()
62
    {
63 29
        $config = $this->getDriverConfig('shorte_st');
64
65 29
        return new ShorteStShortener(
66 29
            $this->app->make(ClientInterface::class),
67 29
            Arr::get($config, 'token')
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($config, 'token') can also be of type null; however, parameter $token of LaraCrafts\UrlShortener\...hortener::__construct() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
            /** @scrutinizer ignore-type */ Arr::get($config, 'token')
Loading history...
68
        );
69
    }
70
71
    /**
72
     * Create an instance of the TinyURL driver.
73
     *
74
     * @return \LaraCrafts\UrlShortener\Http\TinyUrlShortener
75
     */
76 29
    protected function createTinyUrlDriver()
77
    {
78 29
        return new TinyUrlShortener($this->app->make(ClientInterface::class));
79
    }
80
81
    /**
82
     * {@inheritDoc}
83
     */
84
    public function getDefaultDriver()
85
    {
86
        return $this->app['config']['url-shortener.default'];
87
    }
88
89
    /**
90
     * Get the driver configuration.
91
     *
92
     * @param string $name
93
     * @return array
94
     */
95 58
    protected function getDriverConfig(string $name)
96
    {
97 58
        return $this->app['config']["url-shortener.drivers.$name"] ?: [];
98
    }
99
}
100