Completed
Pull Request — master (#24)
by ARCANEDEV
07:36
created

ServiceProvider   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 202
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 14.63%

Importance

Changes 0
Metric Value
dl 0
loc 202
rs 10
c 0
b 0
f 0
ccs 6
cts 41
cp 0.1463
wmc 17
lcom 1
cbo 3

13 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A register() 0 4 1
A boot() 0 4 1
A bind() 0 4 1
A singleton() 0 4 1
A registerProvider() 0 4 1
A registerProviders() 0 6 2
A registerConsoleServiceProvider() 0 7 2
A registerAliases() 0 10 2
A aliases() 0 8 2
A alias() 0 6 1
A config() 0 4 1
A filesystem() 0 4 1
1
<?php namespace Arcanedev\Support;
2
3
use Illuminate\Contracts\Foundation\Application;
4
use Illuminate\Foundation\AliasLoader;
5
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
6
7
/**
8
 * Class     ServiceProvider
9
 *
10
 * @package  Arcanedev\Support\Laravel
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
abstract class ServiceProvider extends IlluminateServiceProvider
14
{
15
    /* -----------------------------------------------------------------
16
     |  Properties
17
     | -----------------------------------------------------------------
18
     */
19
20
    /**
21
     * The application instance.
22
     *
23
     * @var \Illuminate\Foundation\Application
24
     */
25
    protected $app;
26
27
    /**
28
     * The aliases collection.
29
     *
30
     * @var array
31
     */
32
    protected $aliases = [];
33
34
    /**
35
     * Alias loader.
36
     *
37
     * @var \Illuminate\Foundation\AliasLoader
38
     */
39
    private $aliasLoader;
40
41
    /* -----------------------------------------------------------------
42
     |  Constructor
43
     | -----------------------------------------------------------------
44
     */
45
46
    /**
47
     * Create a new service provider instance.
48
     *
49
     * @param  \Illuminate\Contracts\Foundation\Application  $app
50
     */
51 9
    public function __construct(Application $app)
52
    {
53 9
        parent::__construct($app);
54
55 9
        $this->aliasLoader = AliasLoader::getInstance();
56 9
    }
57
58
    /* -----------------------------------------------------------------
59
     |  Main Methods
60
     | -----------------------------------------------------------------
61
     */
62
63
    /**
64
     * Register the service provider.
65
     */
66 9
    public function register()
67
    {
68
        //
69 9
    }
70
71
    /**
72
     * Boot the service provider.
73
     */
74
    public function boot()
75
    {
76
        //
77
    }
78
79
    /**
80
     * Register a binding with the container.
81
     *
82
     * @param  string|array          $abstract
83
     * @param  \Closure|string|null  $concrete
84
     * @param  bool                  $shared
85
     */
86
    public function bind($abstract, $concrete = null, $shared = false)
87
    {
88
        $this->app->bind($abstract, $concrete, $shared);
0 ignored issues
show
Bug introduced by
It seems like $abstract defined by parameter $abstract on line 86 can also be of type array; however, Illuminate\Container\Container::bind() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
89
    }
90
91
    /**
92
     * Register a shared binding in the container.
93
     *
94
     * @param  string|array          $abstract
95
     * @param  \Closure|string|null  $concrete
96
     */
97
    protected function singleton($abstract, $concrete = null)
98
    {
99
        $this->app->singleton($abstract, $concrete);
0 ignored issues
show
Bug introduced by
It seems like $abstract defined by parameter $abstract on line 97 can also be of type array; however, Illuminate\Container\Container::singleton() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
100
    }
101
102
    /**
103
     * Register a service provider.
104
     *
105
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
106
     * @param  array                                       $options
107
     * @param  bool                                        $force
108
     *
109
     * @return \Illuminate\Support\ServiceProvider
110
     */
111
    protected function registerProvider($provider, array $options = [], $force = false)
112
    {
113
        return $this->app->register($provider, $options, $force);
0 ignored issues
show
Documentation introduced by
$options is of type array, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to Application::register() has too many arguments starting with $force.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
114
    }
115
116
    /**
117
     * Register multiple service providers.
118
     *
119
     * @param  array  $providers
120
     */
121
    protected function registerProviders(array $providers)
122
    {
123
        foreach ($providers as $provider) {
124
            $this->registerProvider($provider);
125
        }
126
    }
127
128
    /**
129
     * Register a console service provider.
130
     *
131
     * @param  \Illuminate\Support\ServiceProvider|string  $provider
132
     * @param  array                                       $options
133
     * @param  bool                                        $force
134
     *
135
     * @return \Illuminate\Support\ServiceProvider|null
136
     */
137
    protected function registerConsoleServiceProvider($provider, array $options = [], $force = false)
138
    {
139
        if ($this->app->runningInConsole())
140
            return $this->registerProvider($provider, $options, $force);
141
142
        return null;
143
    }
144
145
    /**
146
     * Register aliases (Facades).
147
     */
148
    protected function registerAliases()
149
    {
150
        $loader = $this->aliasLoader;
151
152
        $this->app->booting(function() use ($loader) {
153
            foreach ($this->aliases as $class => $alias) {
154
                $loader->alias($class, $alias);
155
            }
156
        });
157
    }
158
159
    /**
160
     * Add an aliases to the loader.
161
     *
162
     * @param  array  $aliases
163
     *
164
     * @return self
165
     */
166
    protected function aliases(array $aliases)
167
    {
168
        foreach ($aliases as $class => $alias) {
169
            $this->alias($class, $alias);
170
        }
171
172
        return $this;
173
    }
174
175
    /**
176
     * Add an alias to the loader.
177
     *
178
     * @param  string  $class
179
     * @param  string  $alias
180
     *
181
     * @return self
182
     */
183
    protected function alias($class, $alias)
184
    {
185
        $this->aliases[$class] = $alias;
186
187
        return $this;
188
    }
189
190
    /* -----------------------------------------------------------------
191
     |  Services
192
     | -----------------------------------------------------------------
193
     */
194
195
    /**
196
     * Get the config repository instance.
197
     *
198
     * @return \Illuminate\Config\Repository
199
     */
200
    protected function config()
201
    {
202
        return $this->app['config'];
203
    }
204
205
    /**
206
     * Get the filesystem instance.
207
     *
208
     * @return \Illuminate\Filesystem\Filesystem
209
     */
210
    protected function filesystem()
211
    {
212
        return $this->app['files'];
213
    }
214
}
215