BeesServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 39
rs 10
c 4
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 3 1
A registerFields() 0 14 2
A register() 0 4 1
1
<?php
2
3
namespace Tacone\Bees;
4
5
use App;
6
use Illuminate\Support\ServiceProvider;
7
use Illuminate\Support\Str;
8
use ReflectionClass;
9
10
class BeesServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Indicates if loading of the provider is deferred.
14
     *
15
     * @var bool
16
     */
17
    protected $defer = false;
18
19
    /**
20
     * Bootstrap the application events.
21
     */
22
    public function boot()
23
    {
24
    }
25
26
    protected function registerFields()
27
    {
28
        $namespace = '\\Tacone\\Bees\\Field';
29
        $fields = ['string', 'integer', 'float', 'boolean'];
30
        foreach ($fields as $class) {
31
            App::bind("bees.$class", function ($app, $arguments) use ($class, $namespace) {
32
                $class = Str::studly($class).'Field';
0 ignored issues
show
Bug introduced by
Consider using a different name than the imported variable $class, or did you forget to import by reference?

It seems like you are assigning to a variable which was imported through a use statement which was not imported by reference.

For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.

Change not visible in outer-scope

$x = 1;
$callable = function() use ($x) {
    $x = 2; // Not visible in outer scope. If you would like this, how
            // about using a different variable name than $x?
};

$callable();
var_dump($x); // integer(1)

Change visible in outer-scope

$x = 1;
$callable = function() use (&$x) {
    $x = 2;
};

$callable();
var_dump($x); // integer(2)
Loading history...
33
                $reflect = new ReflectionClass($namespace."\\$class");
34
                $instance = $reflect->newInstanceArgs($arguments);
35
36
                return $instance;
37
            });
38
        }
39
    }
40
41
    /**
42
     * Register the service provider.
43
     */
44
    public function register()
45
    {
46
        $this->registerFields();
47
    }
48
}
49