Completed
Push — master ( 909d61...a1d94d )
by Freek
04:17
created

determineActivityModel()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\Activitylog;
4
5
use Illuminate\Support\ServiceProvider;
6
use Spatie\Activitylog\Exceptions\InvalidConfiguration;
7
use Spatie\Activitylog\Models\Activity;
8
9
class ActivitylogServiceProvider extends ServiceProvider
10
{
11
    /**
12
     * Bootstrap the application events.
13
     */
14
    public function boot()
15
    {
16
        $this->publishes([
17
            __DIR__.'/../config/laravel-activitylog.php' => config_path('laravel-activitylog.php'),
18
        ], 'config');
19
20
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-activitylog.php', 'laravel-activitylog');
21
22
        if (! class_exists('CreateActivityLogTable')) {
23
            $timestamp = date('Y_m_d_His', time());
24
25
            $this->publishes([
26
                __DIR__.'/../migrations/create_activity_log_table.php.stub' => database_path("/migrations/{$timestamp}_create_activity_log_table.php"),
27
            ], 'migrations');
28
        }
29
    }
30
31
    /**
32
     * Register the service provider.
33
     */
34
    public function register()
35
    {
36
        $this->app->bind(
37
            'laravel-activitylog', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
                return self::getActivityModelInstance();
39
            });
40
41
        $this->app->bind('command.activitylog:clean', CleanActivitylogCommand::class);
42
43
        $this->commands([
44
            'command.activitylog:clean',
45
        ]);
46
    }
47
48
    /**
49
     * @throws \Spatie\Activitylog\Exceptions\InvalidConfiguration
50
     *
51
     * @return \Illuminate\Database\Eloquent\Model
52
     */
53
    public static function determineActivityModel()
54
    {
55
        $activityModel = config('laravel-activitylog.activity_model') != null ?
56
            config('laravel-activitylog.activity_model') :
57
            Activity::class;
58
59
        if (! is_a($activityModel, Activity::class, true)) {
60
            throw InvalidConfiguration::modelIsNotValid($activityModel);
61
        }
62
63
        return $activityModel;
64
    }
65
66
    public static function getActivityModelInstance()
67
    {
68
        $activityModelClassName = self::determineActivityModel();
69
70
        return new $activityModelClassName();
71
    }
72
}
73