Passed
Pull Request — master (#24)
by Anton
02:47 queued 28s
created

LoveServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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\Contracts\Love\Reaction\Models\Reaction as ReactionContract;
17
use Cog\Laravel\Love\Console\Commands\Recount;
18
use Cog\Laravel\Love\Console\Commands\UpgradeV5ToV6;
19
use Cog\Laravel\Love\Reaction\Models\Reaction;
20
use Cog\Laravel\Love\Reaction\Observers\ReactionObserver;
21
use Illuminate\Support\ServiceProvider;
22
23
final class LoveServiceProvider extends ServiceProvider
24
{
25
    /**
26
     * Register the service provider.
27
     *
28
     * @return void
29
     */
30
    public function register(): void
31
    {
32
        $this->registerContracts();
33
    }
34
35
    /**
36
     * Bootstrap the application events.
37
     *
38
     * @return void
39
     */
40
    public function boot(): void
41
    {
42
        $this->registerConsoleCommands();
43
        $this->registerObservers();
44
        $this->registerPublishes();
45
        $this->registerMigrations();
46
    }
47
48
    /**
49
     * Register Love's models observers.
50
     *
51
     * @return void
52
     */
53
    private function registerObservers(): void
54
    {
55
        $this->app
56
            ->make(ReactionContract::class)
57
            ->observe(ReactionObserver::class);
0 ignored issues
show
Bug introduced by
The method observe() does not exist on Cog\Contracts\Love\Reaction\Models\Reaction. Since it exists in all sub-types, consider adding an abstract or default implementation to Cog\Contracts\Love\Reaction\Models\Reaction. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
            ->/** @scrutinizer ignore-call */ observe(ReactionObserver::class);
Loading history...
58
    }
59
60
    /**
61
     * Register Love's console commands.
62
     *
63
     * @return void
64
     */
65
    private function registerConsoleCommands(): void
66
    {
67
        if ($this->app->runningInConsole()) {
68
            $this->commands([
69
                Recount::class,
70
                UpgradeV5ToV6::class,
71
            ]);
72
        }
73
    }
74
75
    /**
76
     * Register Love's classes in the container.
77
     *
78
     * @return void
79
     */
80
    private function registerContracts(): void
81
    {
82
        $this->app->bind(ReactionContract::class, Reaction::class);
83
    }
84
85
    /**
86
     * Setup the resource publishing groups for Love.
87
     *
88
     * @return void
89
     */
90
    private function registerPublishes(): void
91
    {
92
        if ($this->app->runningInConsole()) {
93
            $this->publishes([
94
                __DIR__ . '/../database/migrations' => database_path('migrations'),
95
            ], 'love-migrations');
96
        }
97
    }
98
99
    /**
100
     * Register the Love migrations.
101
     *
102
     * @return void
103
     */
104
    private function registerMigrations(): void
105
    {
106
        if ($this->app->runningInConsole()) {
107
            $this->loadMigrationsFrom(__DIR__ . '/../database/migrations');
108
        }
109
    }
110
}
111