Completed
Push — master ( 349901...ea0833 )
by Freek
02:26
created

MediaLibraryServiceProvider::boot()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 22
rs 8.9197
cc 4
eloc 14
nc 4
nop 0
1
<?php
2
3
namespace Spatie\MediaLibrary;
4
5
use Illuminate\Support\ServiceProvider;
6
use Laravel\Lumen\Application as LumenApplication;
7
use Illuminate\Foundation\Application as LaravelApplication;
8
use Spatie\MediaLibrary\Commands\ClearCommand;
9
use Spatie\MediaLibrary\Commands\RegenerateCommand;
10
11
class MediaLibraryServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Indicates if loading of the provider is deferred.
15
     *
16
     * @var bool
17
     */
18
    protected $defer = false;
19
20
    /**
21
     * Bootstrap the application events.
22
     */
23
    public function boot()
24
    {
25
        if ($this->app instanceof LaravelApplication) {
26
            $this->publishes([
27
                __DIR__.'/../config/laravel-medialibrary.php' => config_path('laravel-medialibrary.php'),
28
            ], 'config');
29
30
            if (!class_exists('CreateMediaTable')) {
31
                // Publish the migration
32
                $timestamp = date('Y_m_d_His', time());
33
34
                $this->publishes([
35
                    __DIR__.'/../database/migrations/create_media_table.php.stub' => database_path('migrations/'.$timestamp.'_create_media_table.php'),
36
                  ], 'migrations');
37
            }
38
        } elseif ($this->app instanceof LumenApplication) {
0 ignored issues
show
Bug introduced by
The class Laravel\Lumen\Application does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
39
            $this->app->configure('laravel-medialibrary');
40
        }
41
42
        $mediaClass = config('laravel-medialibrary.media_model');
43
        $mediaClass::observe(new MediaObserver());
44
    }
45
46
    /**
47
     * Register the service provider.
48
     */
49
    public function register()
50
    {
51
        $this->mergeConfigFrom(__DIR__.'/../config/laravel-medialibrary.php', 'laravel-medialibrary');
52
53
        $this->app->singleton(MediaRepository::class);
54
55
        $this->app->bind('command.medialibrary:regenerate', RegenerateCommand::class);
56
        $this->app->bind('command.medialibrary:clear', ClearCommand::class);
57
58
        $this->commands([
59
            'command.medialibrary:regenerate',
60
            'command.medialibrary:clear',
61
        ]);
62
    }
63
}
64