Completed
Pull Request — master (#37)
by
unknown
07:28 queued 06:07
created

CategoriesServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 75
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 12 3
A boot() 0 8 3
A publishResources() 0 13 1
A registerCommands() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Categories\Providers;
6
7
use Rinvex\Categories\Models\Category;
8
use Illuminate\Support\ServiceProvider;
9
use Rinvex\Categories\Console\Commands\MigrateCommand;
10
use Rinvex\Categories\Console\Commands\PublishCommand;
11
use Rinvex\Categories\Console\Commands\RollbackCommand;
12
13
class CategoriesServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * The commands to be registered.
17
     *
18
     * @var array
19
     */
20
    protected $commands = [
21
        MigrateCommand::class => 'command.rinvex.categories.migrate',
22
        PublishCommand::class => 'command.rinvex.categories.publish',
23
        RollbackCommand::class => 'command.rinvex.categories.rollback',
24
    ];
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function register()
30
    {
31
        // Merge config
32
        $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.categories');
33
34
        // Bind eloquent models to IoC container
35
        $this->app->singleton('rinvex.categories.category', $categoryModel = $this->app['config']['rinvex.categories.models.category']);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
36
        $categoryModel === Category::class || $this->app->alias('rinvex.categories.category', Category::class);
37
38
        // Register console commands
39
        ! $this->app->runningInConsole() || $this->registerCommands();
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function boot()
46
    {
47
        // Load migrations
48
        ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations');
49
50
        // Publish Resources
51
        ! $this->app->runningInConsole() || $this->publishResources();
52
    }
53
54
    /**
55
     * Publish resources.
56
     *
57
     * @return void
58
     */
59
    protected function publishResources(): void
60
    {
61
        $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.categories.php')], 'rinvex-categories-config');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 141 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
62
        
63
        $timestamp = date('Y_m_d_His', time());
64
        
65
        $this->publishes([
66
            realpath(__DIR__ . '/../../database/migrations/create_categories_table.php')
67
                => database_path("/migrations/{$timestamp}_create_categories_table.php"),
68
            realpath(__DIR__ . '/../../database/migrations/create_categorizables_table.php')
69
                => database_path("/migrations/{$timestamp}_create_categorizables_table.php"),
70
        ], 'rinvex-categories-migrations');
71
    }
72
73
    /**
74
     * Register console commands.
75
     *
76
     * @return void
77
     */
78
    protected function registerCommands(): void
79
    {
80
        // Register artisan commands
81
        foreach ($this->commands as $key => $value) {
82
            $this->app->singleton($value, $key);
83
        }
84
85
        $this->commands(array_values($this->commands));
86
    }
87
}
88