guardAgainstInvalidSuspensionModel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
namespace Digikraaft\ModelSuspension;
4
5
use Digikraaft\ModelSuspension\Exceptions\InvalidSuspensionModel;
6
use Illuminate\Support\ServiceProvider;
7
8
class ModelSuspensionServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        $this->registerPublishables();
13
    }
14
15
    public function register()
16
    {
17
        $this->mergeConfigFrom(__DIR__ . '/../config/model-suspension.php', 'model-suspension');
18
    }
19
20
    protected function registerPublishables(): void
21
    {
22
        if ($this->app->runningInConsole()) {
23
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations/');
24
        }
25
26
        if (! class_exists('CreateSuspensionsTable')) {
27
            $timestamp = date('Y_m_d_His', time());
28
29
            $this->publishes([
30
                __DIR__ . '/../database/migrations/create_suspensions_table.php.stub' => database_path('migrations/'.$timestamp.'_create_suspensions_table.php'),
31
            ], 'migrations');
32
        }
33
34
        $this->publishes([
35
            __DIR__.'/../config/model-suspension.php' => config_path('model-suspension.php'),
36
        ], 'config');
37
38
        $this->guardAgainstInvalidSuspensionModel();
39
    }
40
41
    public function guardAgainstInvalidSuspensionModel()
42
    {
43
        $modelClassName = config('model-suspension.suspension_model');
44
45
        if (! is_a($modelClassName, Suspension::class, true)) {
46
            throw InvalidSuspensionModel::create($modelClassName);
47
        }
48
    }
49
}
50