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 Raed
14:21
created

UrlShortenerServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
eloc 24
dl 0
loc 74
ccs 28
cts 35
cp 0.8
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 7 1
A publishAssets() 0 8 3
A registerMacros() 0 24 3
1
<?php
2
3
namespace LaraCrafts\UrlShortener;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\ClientInterface;
7
use Illuminate\Routing\UrlGenerator;
8
use Illuminate\Support\ServiceProvider;
9
use Illuminate\Support\Str;
10
use LaraCrafts\UrlShortener\Support\Facades\UrlShortener;
11
12
class UrlShortenerServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Boot package services.
16
     *
17
     * @return void
18
     */
19 45
    public function boot()
20
    {
21 45
        $this->mergeConfigFrom(__DIR__ . '/../config/url-shortener.php', 'url-shortener');
22 45
        $this->publishAssets();
23 45
        $this->registerMacros();
24 45
    }
25
26
    /**
27
     * Publish package assets.
28
     *
29
     * @return void
30
     */
31 45
    protected function publishAssets()
32
    {
33 45
        if (!$this->app->runningInConsole() || Str::contains($this->app->version(), 'Lumen')) {
34
            return;
35
        }
36
37 45
        $this->publishes([
38 45
            __DIR__ . '/../config/url-shortener.php' => config_path('url-shortener.php'),
39
        ]);
40 45
    }
41
42
    /**
43
     * Register package services.
44
     *
45
     * @return void
46
     */
47 45
    public function register()
48
    {
49 45
        $this->app->alias('url.shortener', UrlShortenerManager::class);
50 45
        $this->app->bindIf(ClientInterface::class, Client::class);
51
52 27
        $this->app->singleton('url.shortener', function ($app) {
53 24
            return new UrlShortenerManager($app);
54 45
        });
55 45
    }
56
57
    /**
58
     * Register UrlGenerator macro's.
59
     *
60
     * @return void
61
     */
62 45
    protected function registerMacros()
63
    {
64 45
        if (!class_exists(UrlGenerator::class) || !method_exists(UrlGenerator::class, 'macro')) {
65
            return;
66
        }
67
68 27
        UrlGenerator::macro('shorten', function (...$parameters) {
69
            return app('url.shortener')->shorten(...$parameters);
0 ignored issues
show
Bug introduced by
The method shorten() does not exist on LaraCrafts\UrlShortener\UrlShortenerManager. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

69
            return app('url.shortener')->/** @scrutinizer ignore-call */ shorten(...$parameters);
Loading history...
70 45
        });
71
72 27
        UrlGenerator::macro('shortenAsync', function (...$parameters) {
73
            return app('url.shortener')->shortenAsync(...$parameters);
0 ignored issues
show
Bug introduced by
The method shortenAsync() does not exist on LaraCrafts\UrlShortener\UrlShortenerManager. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

73
            return app('url.shortener')->/** @scrutinizer ignore-call */ shortenAsync(...$parameters);
Loading history...
74 45
        });
75
76 27
        UrlGenerator::macro('shortenUsing', function (string $driver, ...$parameters) {
77
            return app('url.shortener')->shortenUsing($driver, ...$parameters);
0 ignored issues
show
Bug introduced by
$parameters is expanded, but the parameter $url of LaraCrafts\UrlShortener\...Manager::shortenUsing() does not expect variable arguments. ( Ignorable by Annotation )

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

77
            return app('url.shortener')->shortenUsing($driver, /** @scrutinizer ignore-type */ ...$parameters);
Loading history...
78 45
        });
79
80 27
        UrlGenerator::macro('shortenAsyncUsing', function (string $driver, ...$parameters) {
81
            return app('url.shortener')->shortenAsyncUsing($driver, ...$parameters);
0 ignored issues
show
Bug introduced by
$parameters is expanded, but the parameter $url of LaraCrafts\UrlShortener\...er::shortenAsyncUsing() does not expect variable arguments. ( Ignorable by Annotation )

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

81
            return app('url.shortener')->shortenAsyncUsing($driver, /** @scrutinizer ignore-type */ ...$parameters);
Loading history...
82 45
        });
83
84 27
        UrlGenerator::macro('shortener', function () {
85
            return app('url.shortener');
86 45
        });
87 24
    }
88
}
89