MultServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 94
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A publishMigrations() 0 5 1
A packagePath() 0 3 1
A register() 0 3 1
A boot() 0 8 1
A registerCommands() 0 4 1
A loadMigrations() 0 3 1
A publishSeeders() 0 5 1
1
<?php
2
3
namespace Itstructure\Mult;
4
5
use Illuminate\Support\ServiceProvider;
6
use Itstructure\Mult\Commands\{PublishCommand, DatabaseCommand};
7
8
/**
9
 * Class MultServiceProvider
10
 *
11
 * @package Itstructure\Mult
12
 *
13
 * @author Andrey Girnik <[email protected]>
14
 */
15
class MultServiceProvider extends ServiceProvider
16
{
17
    public function register()
18
    {
19
        $this->registerCommands();
20
    }
21
22
    public function boot()
23
    {
24
        // Loading settings
25
        $this->loadMigrations();
26
27
        // Publish settings
28
        $this->publishMigrations();
29
        $this->publishSeeders();
30
    }
31
32
33
    /*
34
    |--------------------------------------------------------------------------
35
    | COMMAND SETTINGS
36
    |--------------------------------------------------------------------------
37
    */
38
39
    /**
40
     * Register commands.
41
     * @return void
42
     */
43
    private function registerCommands(): void
44
    {
45
        $this->commands(Commands\PublishCommand::class);
46
        $this->commands(Commands\DatabaseCommand::class);
47
    }
48
49
50
    /*
51
    |--------------------------------------------------------------------------
52
    | LOADING SETTINGS
53
    |--------------------------------------------------------------------------
54
    */
55
56
    /**
57
     * Set directory to load migrations.
58
     * @return void
59
     */
60
    private function loadMigrations(): void
61
    {
62
        $this->loadMigrationsFrom($this->packagePath('database/migrations'));
63
    }
64
65
66
    /*
67
    |--------------------------------------------------------------------------
68
    | PUBLISH SETTINGS
69
    |--------------------------------------------------------------------------
70
    */
71
72
    /**
73
     * Publish migrations.
74
     * @return void
75
     */
76
    private function publishMigrations(): void
77
    {
78
        $this->publishes([
79
            $this->packagePath('database/migrations') => database_path('migrations'),
80
        ], 'migrations');
81
    }
82
83
    /**
84
     * Publish seeds.
85
     * @return void
86
     */
87
    private function publishSeeders(): void
88
    {
89
        $this->publishes([
90
            $this->packagePath('database/seeders') => database_path('seeders'),
91
        ], 'seeders');
92
    }
93
94
95
    /*
96
    |--------------------------------------------------------------------------
97
    | OTHER SETTINGS
98
    |--------------------------------------------------------------------------
99
    */
100
101
    /**
102
     * Get package path.
103
     * @param $path
104
     * @return string
105
     */
106
    private function packagePath($path): string
107
    {
108
        return __DIR__ . "/../" . $path;
109
    }
110
}
111