AttributesServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 2
cbo 3
dl 0
loc 50
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 7 2
A register() 0 20 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Attributes\Providers;
6
7
use Illuminate\Support\ServiceProvider;
8
use Rinvex\Attributes\Models\Attribute;
9
use Rinvex\Support\Traits\ConsoleTools;
10
use Rinvex\Attributes\Models\AttributeEntity;
11
use Rinvex\Attributes\Console\Commands\MigrateCommand;
12
use Rinvex\Attributes\Console\Commands\PublishCommand;
13
use Rinvex\Attributes\Console\Commands\RollbackCommand;
14
15
class AttributesServiceProvider extends ServiceProvider
16
{
17
    use ConsoleTools;
18
19
    /**
20
     * The commands to be registered.
21
     *
22
     * @var array
23
     */
24
    protected $commands = [
25
        MigrateCommand::class => 'command.rinvex.attributes.migrate',
26
        PublishCommand::class => 'command.rinvex.attributes.publish',
27
        RollbackCommand::class => 'command.rinvex.attributes.rollback',
28
    ];
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function register()
34
    {
35
        // Merge config
36
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.attributes');
37
38
        // Bind eloquent models to IoC container
39
        $this->app->singleton('rinvex.attributes.attribute', $attributeyModel = $this->app['config']['rinvex.attributes.models.attribute']);
40
        $attributeyModel === Attribute::class || $this->app->alias('rinvex.attributes.attribute', Attribute::class);
41
42
        $this->app->singleton('rinvex.attributes.attribute_entity', $attributeEntityModel = $this->app['config']['rinvex.attributes.models.attribute_entity']);
43
        $attributeEntityModel === AttributeEntity::class || $this->app->alias('rinvex.attributes.attribute_entity', AttributeEntity::class);
44
45
        // Register attributes entities
46
        $this->app->singleton('rinvex.attributes.entities', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
            return collect();
48
        });
49
50
        // Register console commands
51
        $this->registerCommands($this->commands);
0 ignored issues
show
Unused Code introduced by
The call to AttributesServiceProvider::registerCommands() has too many arguments starting with $this->commands.

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...
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function boot()
58
    {
59
        // Publish Resources
60
        $this->publishesConfig('rinvex/laravel-attributes');
61
        $this->publishesMigrations('rinvex/laravel-attributes');
62
        ! $this->autoloadMigrations('rinvex/laravel-attributes') || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
63
    }
64
}
65