LoveServiceProvider   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 13
eloc 29
c 3
b 0
f 0
dl 0
loc 89
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A registerConsoleCommands() 0 12 2
A shouldLoadDefaultMigrations() 0 3 1
A registerMigrations() 0 4 3
A configure() 0 4 2
A registerPublishes() 0 10 2
A register() 0 2 1
A registerObservers() 0 3 1
A boot() 0 7 1
1
<?php
2
3
/*
4
 * This file is part of Laravel Love.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Love;
15
16
use Cog\Laravel\Love\Console\Commands\ReactionTypeAdd;
17
use Cog\Laravel\Love\Console\Commands\Recount;
18
use Cog\Laravel\Love\Console\Commands\RegisterReactants;
19
use Cog\Laravel\Love\Console\Commands\RegisterReacters;
20
use Cog\Laravel\Love\Console\Commands\SetupReactable;
21
use Cog\Laravel\Love\Console\Commands\SetupReacterable;
22
use Cog\Laravel\Love\Console\Commands\UpgradeV5ToV6;
23
use Cog\Laravel\Love\Console\Commands\UpgradeV7ToV8;
24
use Cog\Laravel\Love\Reaction\Models\Reaction;
25
use Cog\Laravel\Love\Reaction\Observers\ReactionObserver;
26
use Illuminate\Support\Facades\Config;
27
use Illuminate\Support\ServiceProvider;
28
29
final class LoveServiceProvider extends ServiceProvider
30
{
31
    /**
32
     * Register the service provider.
33
     */
34
    public function register(): void
35
    {
36
    }
37
38
    /**
39
     * Bootstrap the application events.
40
     */
41
    public function boot(): void
42
    {
43
        $this->configure();
44
        $this->registerConsoleCommands();
45
        $this->registerObservers();
46
        $this->registerPublishes();
47
        $this->registerMigrations();
48
    }
49
50
    /**
51
     * Determine if we should register default migrations.
52
     */
53
    private function shouldLoadDefaultMigrations(): bool
54
    {
55
        return Config::get('love.load_default_migrations', true);
56
    }
57
58
    /**
59
     * Register Love's models observers.
60
     */
61
    private function registerObservers(): void
62
    {
63
        Reaction::observe(ReactionObserver::class);
64
    }
65
66
    /**
67
     * Register Love's console commands.
68
     */
69
    private function registerConsoleCommands(): void
70
    {
71
        if ($this->app->runningInConsole()) {
72
            $this->commands([
73
                ReactionTypeAdd::class,
74
                Recount::class,
75
                SetupReactable::class,
76
                SetupReacterable::class,
77
                RegisterReactants::class,
78
                RegisterReacters::class,
79
                UpgradeV5ToV6::class,
80
                UpgradeV7ToV8::class,
81
            ]);
82
        }
83
    }
84
85
    /**
86
     * Setup the resource publishing groups for Love.
87
     */
88
    private function registerPublishes(): void
89
    {
90
        if ($this->app->runningInConsole()) {
91
            $this->publishes([
92
                __DIR__ . '/../config/love.php' => config_path('love.php'),
93
            ], 'love-config');
94
95
            $this->publishes([
96
                __DIR__ . '/../database/migrations' => database_path('migrations'),
97
            ], 'love-migrations');
98
        }
99
    }
100
101
    /**
102
     * Register the Love migrations.
103
     */
104
    private function registerMigrations(): void
105
    {
106
        if ($this->app->runningInConsole() && $this->shouldLoadDefaultMigrations()) {
107
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
108
        }
109
    }
110
111
    /**
112
     * Merge Love configuration with the application configuration.
113
     */
114
    private function configure(): void
115
    {
116
        if (!$this->app->configurationIsCached()) {
117
            $this->mergeConfigFrom(__DIR__ . '/../config/love.php', 'love');
118
        }
119
    }
120
}
121