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 ( c54690...2499fd )
by Choraimy
07:29 queued 27s
created

UrlShortenerManager::createIsGdDriver()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

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

33
            /** @scrutinizer ignore-type */ Arr::get($config, 'token'),
Loading history...
34 24
            Arr::get($config, 'domain', 'bit.ly')
35
        );
36
    }
37
38
    /**
39
     * {@inheritDoc}
40
     */
41 144
    protected function createDriver($driver)
42
    {
43
        # This fixes backwards compatibility issues with this function
44 144
        if (method_exists($this, $method = 'create' . Str::studly($driver) . 'Driver')) {
45 144
            return $this->$method();
46
        }
47
48
        return parent::createDriver($driver);
49
    }
50
51
    /**
52
     * Create an instance of the Is.gd driver.
53
     *
54
     * @return \LaraCrafts\UrlShortener\Http\IsGdShortener
55
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
56
     */
57 24
    protected function createIsGdDriver()
58
    {
59 24
        $config = $this->getDriverConfig('is_gd');
60
61 24
        return new IsGdShortener(
62 24
            $this->app->make(ClientInterface::class),
63 24
            Arr::get($config, 'link_previews'),
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::...onfig, 'link_previews') can also be of type null; however, parameter $linkPreviews of LaraCrafts\UrlShortener\...hortener::__construct() does only seem to accept boolean, 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

63
            /** @scrutinizer ignore-type */ Arr::get($config, 'link_previews'),
Loading history...
64 24
            Arr::get($config, 'statistics')
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::...($config, 'statistics') can also be of type null; however, parameter $statistics of LaraCrafts\UrlShortener\...hortener::__construct() does only seem to accept boolean, 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

64
            /** @scrutinizer ignore-type */ Arr::get($config, 'statistics')
Loading history...
65
        );
66
    }
67
68
    /**
69
     * Create an instance of the Ouo.io driver.
70
     *
71
     * @return \LaraCrafts\UrlShortener\Http\OuoIoShortener
72
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
73
     */
74 24
    protected function createOuoIoDriver()
75
    {
76 24
        $config = $this->getDriverConfig('ouo_io');
77
78 24
        return new OuoIoShortener(
79 24
            $this->app->make(ClientInterface::class),
80 24
            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

80
            /** @scrutinizer ignore-type */ Arr::get($config, 'token')
Loading history...
81
        );
82
    }
83
84
    /**
85
     * Create an instance of the Shorte.st driver.
86
     *
87
     * @return \LaraCrafts\UrlShortener\Http\ShorteStShortener
88
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
89
     */
90 24
    protected function createShorteStDriver()
91
    {
92 24
        $config = $this->getDriverConfig('shorte_st');
93
94 24
        return new ShorteStShortener(
95 24
            $this->app->make(ClientInterface::class),
96 24
            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

96
            /** @scrutinizer ignore-type */ Arr::get($config, 'token')
Loading history...
97
        );
98
    }
99
100
    /**
101
     * Create an instance of the TinyURL driver.
102
     *
103
     * @return \LaraCrafts\UrlShortener\Http\TinyUrlShortener
104
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
105
     */
106 48
    protected function createTinyUrlDriver()
107
    {
108 48
        return new TinyUrlShortener($this->app->make(ClientInterface::class));
109
    }
110
111
    /**
112
     * {@inheritDoc}
113
     */
114 24
    public function getDefaultDriver()
115
    {
116 24
        return $this->app['config']['url-shortener.default'];
117
    }
118
119
    /**
120
     * Get the driver configuration.
121
     *
122
     * @param string $name
123
     * @return array
124
     */
125 96
    protected function getDriverConfig(string $name)
126
    {
127 96
        return $this->app['config']["url-shortener.drivers.$name"] ?: [];
128
    }
129
}
130