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 ( bd35eb...e9c3bd )
by Choraimy
07:33
created

UrlShortenerServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 82.76%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 66
ccs 24
cts 29
cp 0.8276
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 16 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
11
class UrlShortenerServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Boot package services.
15
     *
16
     * @return void
17
     */
18 52
    public function boot()
19
    {
20 52
        $this->mergeConfigFrom(__DIR__ . '/../config/url-shortener.php', 'url-shortener');
21 52
        $this->publishAssets();
22 52
        $this->registerMacros();
23 52
    }
24
25
    /**
26
     * Publish package assets.
27
     *
28
     * @return void
29
     */
30 52
    protected function publishAssets()
31
    {
32 52
        if (!$this->app->runningInConsole() || Str::contains($this->app->version(), 'Lumen')) {
33
            return;
34
        }
35
36 52
        $this->publishes([
37 52
            __DIR__ . '/../config/url-shortener.php' => config_path('url-shortener.php'),
38
        ]);
39 52
    }
40
41
    /**
42
     * Register package services.
43
     *
44
     * @return void
45
     */
46 52
    public function register()
47
    {
48 52
        $this->app->alias('url.shortener', UrlShortenerManager::class);
49 52
        $this->app->bindIf(ClientInterface::class, Client::class);
50
51 48
        $this->app->singleton('url.shortener', function ($app) {
52 29
            return new UrlShortenerManager($app);
53 52
        });
54 52
    }
55
56
    /**
57
     * Register UrlGenerator macro's.
58
     *
59
     * @return void
60
     */
61 52
    protected function registerMacros()
62
    {
63 52
        if (!class_exists(UrlGenerator::class) || !method_exists(UrlGenerator::class, 'macro')) {
64
            return;
65
        }
66
67 48
        UrlGenerator::macro('shorten', function (...$parameters) {
68
            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

68
            return app('url.shortener')->/** @scrutinizer ignore-call */ shorten(...$parameters);
Loading history...
69 52
        });
70
71 48
        UrlGenerator::macro('shortenAsync', function (...$parameters) {
72
            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

72
            return app('url.shortener')->/** @scrutinizer ignore-call */ shortenAsync(...$parameters);
Loading history...
73 52
        });
74
75 48
        UrlGenerator::macro('shortener', function () {
76
            return app('url.shortener');
77 52
        });
78 10
    }
79
}
80