UrlShortenerServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 6
Bugs 1 Features 1
Metric Value
wmc 7
c 6
b 1
f 1
lcom 1
cbo 2
dl 0
loc 106
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 1
A register() 0 23 1
A provides() 0 4 1
A configPublisher() 0 7 1
A facadeBindings() 0 13 1
A implementationBindings() 0 7 1
A serviceProviders() 0 4 1
1
<?php
2
3
namespace Vinelab\UrlShortener;
4
5
use Illuminate\Support\ServiceProvider;
6
7
/**
8
 * Class UrlShortenerServiceProvider.
9
 *
10
 * @category The package service provider
11
 *
12
 * @author   Mahmoud Zalt <[email protected]>
13
 */
14
class UrlShortenerServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = false;
22
23
    /**
24
     * Boot the package.
25
     */
26
    public function boot()
27
    {
28
        /*
29
        |--------------------------------------------------------------------------
30
        | Publish the Config file from the Package to the App directory
31
        |--------------------------------------------------------------------------
32
        */
33
        $this->configPublisher();
34
    }
35
36
    /**
37
     * Register the service provider.
38
     */
39
    public function register()
40
    {
41
        /*
42
        |--------------------------------------------------------------------------
43
        | Implementation Bindings
44
        |--------------------------------------------------------------------------
45
        */
46
        $this->implementationBindings();
47
48
        /*
49
        |--------------------------------------------------------------------------
50
        | Facade Bindings
51
        |--------------------------------------------------------------------------
52
        */
53
        $this->facadeBindings();
54
55
        /*
56
        |--------------------------------------------------------------------------
57
        | Registering Service Providers
58
        |--------------------------------------------------------------------------
59
        */
60
        $this->serviceProviders();
0 ignored issues
show
Unused Code introduced by
The call to the method Vinelab\UrlShortener\Url...der::serviceProviders() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
61
    }
62
63
    /**
64
     * Get the services provided by the provider.
65
     *
66
     * @return array
67
     */
68
    public function provides()
69
    {
70
        return [];
71
    }
72
73
    /**
74
     * Publish the Config file from the Package to the App directory.
75
     */
76
    private function configPublisher()
77
    {
78
        // When users execute Laravel's vendor:publish command, the config file will be copied to the specified location
79
        $this->publishes([
80
            __DIR__.'/Config/url-shortener.php' => config_path('url-shortener.php'),
81
        ]);
82
    }
83
84
    /**
85
     * Facades Binding.
86
     */
87
    private function facadeBindings()
88
    {
89
        // Register 'vinelab.shorten' instance container
90
        $this->app['vinelab.shorten'] = $this->app->share(function ($app) {
0 ignored issues
show
Bug introduced by
The method share() does not seem to exist on object<Illuminate\Contra...Foundation\Application>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
91
            return $app->make('Vinelab\UrlShortener\Shorten');
92
        });
93
94
        // Register 'Shorten' Alias, So users don't have to add the Alias to the 'app/config/app.php'
95
        $this->app->booting(function () {
96
            $loader = \Illuminate\Foundation\AliasLoader::getInstance();
97
            $loader->alias('Shorten', 'Vinelab\UrlShortener\Facades\ShortenFacadeAccessor');
98
        });
99
    }
100
101
    /**
102
     * Implementation Bindings.
103
     */
104
    private function implementationBindings()
105
    {
106
        $this->app->bind(
107
            'Vinelab\UrlShortener\Contracts\ShortenInterface',
108
            'Vinelab\UrlShortener\Shorten'
109
        );
110
    }
111
112
    /**
113
     * Registering Other Custom Service Providers.
114
     */
115
    private function serviceProviders()
116
    {
117
        //        $this->app->register('Vinelab\...\...');
118
    }
119
}
120