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 (#15)
by Choraimy
16:41 queued 14:17
created

UrlShortenerManager::getDriverConfig()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
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\FirebaseShortener;
12
use LaraCrafts\UrlShortener\Http\IsGdShortener;
13
use LaraCrafts\UrlShortener\Http\OuoIoShortener;
14
use LaraCrafts\UrlShortener\Http\ShorteStShortener;
15
use LaraCrafts\UrlShortener\Http\TinyUrlShortener;
16
17
/**
18
 * @mixin \LaraCrafts\UrlShortener\Contracts\Shortener
19
 */
20
class UrlShortenerManager extends Manager implements Factory
21
{
22
    /**
23
     * Shorten the given URL using the given driver.
24
     *
25
     * @param string $driver
26
     * @param string $url
27
     * @param array $options
28
     *
29
     * @return string
30
     */
31
    public function shortenUsing(string $driver, string $url, array $options = [])
32
    {
33
        return $this->driver($driver)->shorten($url, $options);
34
    }
35
36
    /**
37
     * Shorten the given URL asynchronously using the given driver.
38
     *
39
     * @param string $driver
40
     * @param string $url
41
     * @param array $options
42
     *
43
     * @return \GuzzleHttp\Promise\PromisorInterface
44
     */
45
    public function shortenAsyncUsing(string $driver, string $url, array $options = [])
46
    {
47
        return $this->driver($driver)->shortenAsync($url, $options);
48
    }
49
50
    /**
51
     * Create an instance of the Bit.ly driver.
52
     *
53
     * @return \LaraCrafts\UrlShortener\Http\BitLyShortener
54
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
55
     */
56 24
    protected function createBitLyDriver()
57
    {
58 24
        $config = $this->getDriverConfig('bit_ly');
59
60 24
        return new BitLyShortener(
61 24
            $this->app->make(ClientInterface::class),
62 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

62
            /** @scrutinizer ignore-type */ Arr::get($config, 'token'),
Loading history...
63 24
            Arr::get($config, 'domain', 'bit.ly')
64
        );
65
    }
66
67
    /**
68
     * {@inheritDoc}
69
     */
70 168
    protected function createDriver($driver)
71
    {
72
        # This fixes backwards compatibility issues with this function
73 168
        if (method_exists($this, $method = 'create' . Str::studly($driver) . 'Driver')) {
74 168
            return $this->$method();
75
        }
76
77
        return parent::createDriver($driver);
78
    }
79
80
    /**
81
     * Create an instance of the Firebase driver.
82
     *
83
     * @return \LaraCrafts\UrlShortener\Http\FirebaseShortener
84
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
85
     */
86 24
    protected function createFirebaseDriver()
87
    {
88 24
        $config = $this->getDriverConfig('firebase');
89
90 24
        return new FirebaseShortener(
91 24
            $this->app->make(ClientInterface::class),
92 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

92
            /** @scrutinizer ignore-type */ Arr::get($config, 'token'),
Loading history...
93 24
            Arr::get($config, 'prefix'),
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($config, 'prefix') can also be of type null; however, parameter $domain 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

93
            /** @scrutinizer ignore-type */ Arr::get($config, 'prefix'),
Loading history...
94 24
            Arr::get($config, 'suffix')
0 ignored issues
show
Bug introduced by
It seems like Illuminate\Support\Arr::get($config, 'suffix') can also be of type null; however, parameter $suffix 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

94
            /** @scrutinizer ignore-type */ Arr::get($config, 'suffix')
Loading history...
95
        );
96
    }
97
98
    /**
99
     * Create an instance of the Is.gd driver.
100
     *
101
     * @return \LaraCrafts\UrlShortener\Http\IsGdShortener
102
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
103
     */
104 24
    protected function createIsGdDriver()
105
    {
106 24
        $config = $this->getDriverConfig('is_gd');
107
108 24
        return new IsGdShortener(
109 24
            $this->app->make(ClientInterface::class),
110 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

110
            /** @scrutinizer ignore-type */ Arr::get($config, 'link_previews'),
Loading history...
111 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

111
            /** @scrutinizer ignore-type */ Arr::get($config, 'statistics')
Loading history...
112
        );
113
    }
114
115
    /**
116
     * Create an instance of the Ouo.io driver.
117
     *
118
     * @return \LaraCrafts\UrlShortener\Http\OuoIoShortener
119
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
120
     */
121 24
    protected function createOuoIoDriver()
122
    {
123 24
        $config = $this->getDriverConfig('ouo_io');
124
125 24
        return new OuoIoShortener(
126 24
            $this->app->make(ClientInterface::class),
127 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

127
            /** @scrutinizer ignore-type */ Arr::get($config, 'token')
Loading history...
128
        );
129
    }
130
131
    /**
132
     * Create an instance of the Shorte.st driver.
133
     *
134
     * @return \LaraCrafts\UrlShortener\Http\ShorteStShortener
135
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
136
     */
137 24
    protected function createShorteStDriver()
138
    {
139 24
        $config = $this->getDriverConfig('shorte_st');
140
141 24
        return new ShorteStShortener(
142 24
            $this->app->make(ClientInterface::class),
143 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

143
            /** @scrutinizer ignore-type */ Arr::get($config, 'token')
Loading history...
144
        );
145
    }
146
147
    /**
148
     * Create an instance of the TinyURL driver.
149
     *
150
     * @return \LaraCrafts\UrlShortener\Http\TinyUrlShortener
151
     * @throws \Illuminate\Contracts\Container\BindingResolutionException
152
     */
153 48
    protected function createTinyUrlDriver()
154
    {
155 48
        return new TinyUrlShortener($this->app->make(ClientInterface::class));
156
    }
157
158
    /**
159
     * {@inheritDoc}
160
     */
161 24
    public function getDefaultDriver()
162
    {
163 24
        return $this->app['config']['url-shortener.default'];
164
    }
165
166
    /**
167
     * Get the driver configuration.
168
     *
169
     * @param string $name
170
     * @return array
171
     */
172 120
    protected function getDriverConfig(string $name)
173
    {
174 120
        return $this->app['config']["url-shortener.drivers.$name"] ?: [];
175
    }
176
}
177