LaravelMessageServiceServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 86
rs 10
c 0
b 0
f 0
ccs 0
cts 47
cp 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 16 2
A register() 0 3 1
A registerMigrations() 0 10 2
A loadMigrationsFrom() 0 8 2
A registerCommands() 0 11 2
A registerJobs() 0 6 1
1
<?php
2
3
namespace Alive2212\LaravelMessageService;
4
5
use Alive2212\LaravelMessageService\Console\InstallCommand;
6
use Alive2212\LaravelMessageService\Providers\AliveLaravelMessageServiceRouteServiceProvider;
7
use Illuminate\Support\ServiceProvider;
8
9
class LaravelMessageServiceServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Perform post-registration booting of services.
13
     *
14
     * @return void
15
     */
16
    public function boot()
17
    {
18
        $this->app->register(AliveLaravelMessageServiceRouteServiceProvider::class);
19
20
        if ($this->app->runningInConsole()) {
21
22
            // register jobs
23
            $this->registerJobs();
24
25
            // register migrations
26
            $this->registerMigrations();
27
28
            // register all commands into 'Console' folder
29
            $this->registerCommands();
30
        }
31
    }
32
33
    /**
34
     * Register any package services.
35
     *
36
     * @return void
37
     */
38
    public function register()
39
    {
40
    }
41
42
    /**
43
     * Register Package's migration files.
44
     *
45
     * @return void
46
     */
47
    protected function registerMigrations()
48
    {
49
        if (LaravelMessageService::$runsMigrations) {
0 ignored issues
show
Bug introduced by
The property runsMigrations cannot be accessed from this context as it is declared private in class Alive2212\LaravelMessage...e\LaravelMessageService.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
50
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
51
            return;
52
        }
53
        $this->publishes([
54
            __DIR__ . '/../database/migrations' => database_path('migrations'),
55
        ], 'message-service');
56
    }
57
58
    /**
59
     * Register a database migration path.
60
     *
61
     * @param  array|string $paths
62
     * @return void
63
     */
64
    protected function loadMigrationsFrom($paths)
65
    {
66
        $this->app->afterResolving('migrator', function ($migrator) use ($paths) {
67
            foreach ((array)$paths as $path) {
68
                $migrator->path($path);
69
            }
70
        });
71
    }
72
73
    public function registerCommands()
74
    {
75
        $consoles = scandir(__DIR__ . '/Console');
76
        $commands = [];
77
        unset($consoles[0], $consoles[1]);
78
        foreach ($consoles as $console) {
79
            $dir = __NAMESPACE__ . '\\Console\\' . str_replace(".php", "", $console);
80
            array_push($commands, $dir);
81
        }
82
        $this->commands($commands);
83
    }
84
85
    /**
86
     *
87
     */
88
    public function registerJobs()
89
    {
90
        $this->publishes([
91
            __DIR__ . '/Jobs' => app_path('Jobs'),
92
        ], "message-service");
93
    }
94
}