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 ( 2d9704...bd35eb )
by Choraimy
07:37
created

UrlShortenerManager::getDefaultDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
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 LaraCrafts\UrlShortener\Contracts\Factory;
10
use LaraCrafts\UrlShortener\Http\BitLyShortener;
11
use LaraCrafts\UrlShortener\Http\ShorteStShortener;
12
use LaraCrafts\UrlShortener\Http\TinyUrlShortener;
13
14
/**
15
 * @mixin \LaraCrafts\UrlShortener\Contracts\Shortener
16
 */
17
class UrlShortenerManager extends Manager implements Factory
18
{
19
    /**
20
     * Create an instance of the Bit.ly driver.
21
     *
22
     * @return \LaraCrafts\UrlShortener\Http\BitLyShortener
23
     */
24 58
    protected function createBitLyDriver()
25
    {
26 58
        $config = $this->getDriverConfig('bit_ly');
27
28 58
        return new BitLyShortener(
29 58
            $this->app->make(ClientInterface::class),
30 58
            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

30
            /** @scrutinizer ignore-type */ Arr::get($config, 'token'),
Loading history...
31 58
            Arr::get($config, 'domain', 'bit.ly')
32
        );
33
    }
34
35
    /**
36
     * {@inheritDoc}
37
     */
38 116
    protected function createDriver($driver)
39
    {
40
        # This fixes backwards compatibility issues with this function
41 116
        if (method_exists($this, $method = 'create' . Str::studly($driver) . 'Driver')) {
42 116
            return $this->$method();
43
        }
44
45
        return parent::createDriver($driver);
46
    }
47
48
    /**
49
     * Create a new instance of the Shorte.st driver.
50
     *
51
     * @return \LaraCrafts\UrlShortener\Http\ShorteStShortener
52
     */
53 29
    protected function createShorteStDriver()
54
    {
55 29
        $config = $this->getDriverConfig('shorte_st');
56
57 29
        return new ShorteStShortener(
58 29
            $this->app->make(ClientInterface::class),
59 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

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