ModelStatusServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 20 3
A register() 0 4 1
A guardAgainstInvalidStatusModel() 0 8 2
1
<?php
2
3
namespace Spatie\ModelStatus;
4
5
use Illuminate\Support\ServiceProvider;
6
use Spatie\ModelStatus\Exceptions\InvalidStatusModel;
7
8
class ModelStatusServiceProvider extends ServiceProvider
9
{
10
    public function boot()
11
    {
12
        if ($this->app->runningInConsole()) {
13
            $this->loadMigrationsFrom(__DIR__.'/../database/migrations/');
14
        }
15
16
        if (! class_exists('CreateStatusesTable')) {
17
            $timestamp = date('Y_m_d_His', time());
18
19
            $this->publishes([
20
                __DIR__.'/../database/migrations/create_statuses_table.php.stub' => database_path('migrations/'.$timestamp.'_create_statuses_table.php'),
21
            ], 'migrations');
22
        }
23
24
        $this->publishes([
25
            __DIR__.'/../config/model-status.php' => config_path('model-status.php'),
26
        ], 'config');
27
28
        $this->guardAgainstInvalidStatusModel();
29
    }
30
31
    public function register()
32
    {
33
        $this->mergeConfigFrom(__DIR__.'/../config/model-status.php', 'model-status');
34
    }
35
36
    public function guardAgainstInvalidStatusModel()
37
    {
38
        $modelClassName = config('model-status.status_model');
39
40
        if (! is_a($modelClassName, Status::class, true)) {
41
            throw InvalidStatusModel::create($modelClassName);
42
        }
43
    }
44
}
45