Completed
Pull Request — master (#37)
by
unknown
13:42
created

CategoriesServiceProvider::publishResources()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
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(
67
                __DIR__ . '/../../database/migrations/create_categories_table.php'
68
                    => database_path("/migrations/{$timestamp}_create_categories_table.php")
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_DOUBLE_ARROW, expecting ',' or ')'
Loading history...
69
            ),
70
            realpath(
71
                __DIR__ . '/../../database/migrations/create_categorizables_table.php'
72
                    => database_path("/migrations/{$timestamp}_create_categorizables_table.php")
73
            ),
74
        ], 'rinvex-categories-migrations');
75
    }
76
77
    /**
78
     * Register console commands.
79
     *
80
     * @return void
81
     */
82
    protected function registerCommands(): void
83
    {
84
        // Register artisan commands
85
        foreach ($this->commands as $key => $value) {
86
            $this->app->singleton($value, $key);
87
        }
88
89
        $this->commands(array_values($this->commands));
90
    }
91
}
92