Completed
Push — 2.0 ( 9e2b8d )
by Nicolas
03:40
created

MediaServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 6
nc 1
nop 1
1
<?php namespace Modules\Media\Providers;
2
3
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
4
use Illuminate\Support\Facades\Validator;
5
use Illuminate\Support\ServiceProvider;
6
use Modules\Media\Console\RefreshThumbnailCommand;
7
use Modules\Media\Entities\File;
8
use Modules\Media\Events\Handlers\HandleMediaStorage;
9
use Modules\Media\Events\Handlers\RemovePolymorphicLink;
10
use Modules\Media\Repositories\Eloquent\EloquentFileRepository;
11
use Modules\Media\Repositories\FileRepository;
12
13
class MediaServiceProvider extends ServiceProvider
14
{
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = false;
21
22
    /**
23
     * Register the service provider.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->registerBindings();
30
31
        $this->registerCommands();
32
    }
33
34
    public function boot(DispatcherContract $events)
35
    {
36
        $this->registerMaxFolderSizeValidator();
37
38
        $this->mergeConfigFrom(__DIR__ . '/../Config/config.php', 'asgard.media.config');
39
        $this->publishes([__DIR__ . '/../Config/config.php' => config_path('asgard.media.config' . '.php'), ], 'config');
40
41
        $events->listen('*', HandleMediaStorage::class);
42
        $events->listen('*', RemovePolymorphicLink::class);
43
    }
44
45
    /**
46
     * Get the services provided by the provider.
47
     *
48
     * @return array
49
     */
50
    public function provides()
51
    {
52
        return array();
53
    }
54
55
    private function registerBindings()
56
    {
57
        $this->app->bind(FileRepository::class, function ($app) {
58
            return new EloquentFileRepository(new File(), $app['filesystem.disk']);
0 ignored issues
show
Documentation introduced by
new \Modules\Media\Entities\File() is of type object<Modules\Media\Entities\File>, but the function expects a object<Modules\Core\Repositories\Eloquent\Model>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
The call to EloquentFileRepository::__construct() has too many arguments starting with $app['filesystem.disk'].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
59
        });
60
    }
61
62
    /**
63
     * Register all commands for this module
64
     */
65
    private function registerCommands()
66
    {
67
        $this->registerRefreshCommand();
68
    }
69
70
    /**
71
     * Register the refresh thumbnails command
72
     */
73
    private function registerRefreshCommand()
74
    {
75
        $this->app->bindShared('command.media.refresh', function ($app) {
76
            return new RefreshThumbnailCommand($app['Modules\Media\Repositories\FileRepository']);
77
        });
78
79
        $this->commands('command.media.refresh');
80
    }
81
82
    private function registerMaxFolderSizeValidator()
83
    {
84
        Validator::extend('max_size', '\Modules\Media\Validators\MaxFolderSizeValidator@validateMaxSize');
85
    }
86
}
87