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
04:52
created

UrlShortenerServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 80.56%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 76
ccs 29
cts 36
cp 0.8056
rs 10
c 0
b 0
f 0
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 7 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
25 45
        UrlShortener::shortenUsing('bit_ly', 'https://google.com');
26 45
    }
27
28
    /**
29
     * Publish package assets.
30
     *
31
     * @return void
32
     */
33 45
    protected function publishAssets()
34
    {
35 45
        if (!$this->app->runningInConsole() || Str::contains($this->app->version(), 'Lumen')) {
36
            return;
37
        }
38
39 45
        $this->publishes([
40 45
            __DIR__ . '/../config/url-shortener.php' => config_path('url-shortener.php'),
41
        ]);
42 45
    }
43
44
    /**
45
     * Register package services.
46
     *
47
     * @return void
48
     */
49 45
    public function register()
50
    {
51 45
        $this->app->alias('url.shortener', UrlShortenerManager::class);
52 45
        $this->app->bindIf(ClientInterface::class, Client::class);
53
54 27
        $this->app->singleton('url.shortener', function ($app) {
55 45
            return new UrlShortenerManager($app);
56 45
        });
57 45
    }
58
59
    /**
60
     * Register UrlGenerator macro's.
61
     *
62
     * @return void
63
     */
64 45
    protected function registerMacros()
65
    {
66 45
        if (!class_exists(UrlGenerator::class) || !method_exists(UrlGenerator::class, 'macro')) {
67
            return;
68
        }
69
70 27
        UrlGenerator::macro('shorten', function (...$parameters) {
71
            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

71
            return app('url.shortener')->/** @scrutinizer ignore-call */ shorten(...$parameters);
Loading history...
72 45
        });
73
74 27
        UrlGenerator::macro('shortenAsync', function (...$parameters) {
75
            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

75
            return app('url.shortener')->/** @scrutinizer ignore-call */ shortenAsync(...$parameters);
Loading history...
76 45
        });
77
78 27
        UrlGenerator::macro('shortenUsing', function (string $driver, ...$parameters) {
79
            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

79
            return app('url.shortener')->shortenUsing($driver, /** @scrutinizer ignore-type */ ...$parameters);
Loading history...
80 45
        });
81
82 27
        UrlGenerator::macro('shortenAsyncUsing', function (string $driver, ...$parameters) {
83
            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

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