ServiceProvider::bootCommands()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace LaravelSynchronize\Providers;
4
5
use LaravelSynchronize\Console\Commands\SynchronizeCommand;
6
use Illuminate\Support\ServiceProvider as BaseServiceProvider;
7
use LaravelSynchronize\Console\Commands\MakeSynchronizationCommand;
8
9
/**
10
 * Service provider
11
 */
12
class ServiceProvider extends BaseServiceProvider
13
{
14
    /**
15
     * Bootstrap the application services.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        $this->registerPublishments();
22
23
        $this->bootCommands();
24
    }
25
26
    /**
27
     * Register any application services.
28
     *
29
     * @return void
30
     */
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(
34
            $this->getDefaultConfigFilePath('synchronizer'),
35
            'synchronizer'
36
        );
37
38
        $this->app->register(LaravelSynchronizeEventServiceProvider::class);
39
    }
40
41
    /**
42
     * Register publishments
43
     *
44
     * @return void
45
     */
46
    protected function registerPublishments()
47
    {
48
        $this->publishes([
49
            __DIR__ . '/../config/synchronizer.php' => config_path('synchronizer.php'),
50
        ], 'config');
51
52
        $this->publishes([
53
            __DIR__ . '/../database/migrations/' => database_path('migrations'),
54
        ], 'migrations');
55
    }
56
57
    /**
58
     * Get default configuration file path
59
     *
60
     * @return string
61
     */
62
    public function getDefaultConfigFilePath($configName)
63
    {
64
        return realpath(__DIR__ . "/../config/{$configName}.php");
65
    }
66
67
    /**
68
     * Boot commands
69
     *
70
     * @return void
71
     */
72
    private function bootCommands()
73
    {
74
        if ($this->app->runningInConsole()) {
75
            $this->commands([
76
                MakeSynchronizationCommand::class,
77
                SynchronizeCommand::class,
78
            ]);
79
        }
80
    }
81
}
82