ImageServiceProvider::loadHelpers()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 1
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace OkayBueno\Images;
4
5
use Illuminate\Support\ServiceProvider;
6
use Intervention\Image\ImageManager;
7
use OkayBueno\Images\Services\ImageServiceInterface;
8
use OkayBueno\Images\Services\ImageProcessingServiceInterface;
9
use OkayBueno\Images\Services\src\ImageProcessingService;
10
use OkayBueno\Images\Services\src\ImageService;
11
use OkayBueno\Images\Services\Validation\ImageValidatorInterface;
12
use OkayBueno\Images\Services\Validation\src\ImageValidatorLaravel;
13
14
/**
15
 * Class ImagingServiceProvider
16
 * @package OkayBueno\Images
17
 */
18
class ImageServiceProvider extends ServiceProvider
19
{
20
21
    private $configPath = '/config/images.php';
22
23
24
    /**
25
     *
26
     */
27
    public function boot()
28
    {
29
        $this->publishes([
30
            __DIR__.$this->configPath => config_path('images.php'),
0 ignored issues
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

30
            __DIR__.$this->configPath => /** @scrutinizer ignore-call */ config_path('images.php'),
Loading history...
31
        ], 'images');
32
33
        $this->loadMigrationsFrom( __DIR__.'/migrations' );
34
    }
35
36
37
    /**
38
     *
39
     */
40
    public function register()
41
    {
42
        // merge default config
43
        $this->mergeConfigFrom(
44
            __DIR__.$this->configPath , 'images'
45
        );
46
47
        // Bindings.
48
        $this->bindValidators();
49
        $this->bindImageProcessor();
50
        $this->bindImageService();
51
52
        $this->loadHelpers();
53
54
        // And commands.
55
        $this->registerPurgeImagesCommand();
56
        $this->registerResizeImageCommand();
57
    }
58
59
60
    /**
61
     *
62
     */
63
    private function bindImageProcessor()
64
    {
65
        // Bind the image processing service.
66
        $this->app->bind( ImageProcessingServiceInterface::class, function ( $app )
0 ignored issues
show
Unused Code introduced by
The parameter $app is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

66
        $this->app->bind( ImageProcessingServiceInterface::class, function ( /** @scrutinizer ignore-unused */ $app )

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

Loading history...
67
        {
68
            // create an image manager instance with favored driver
69
            $config = [
70
                'driver' => config('images.driver', 'gd')
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

70
                'driver' => /** @scrutinizer ignore-call */ config('images.driver', 'gd')
Loading history...
71
            ];
72
73
            $imageManager = new ImageManager( $config );
74
75
            return new ImageProcessingService( $imageManager );
76
        });
77
    }
78
79
    /**
80
     *
81
     */
82
    private function bindValidators()
83
    {
84
        // Bind the image service.
85
        $this->app->bind( ImageValidatorInterface::class, function ( $app )
86
        {
87
            return $app->make( ImageValidatorLaravel::class );
88
        });
89
    }
90
91
    /**
92
     *
93
     */
94
    private function bindImageService()
95
    {
96
        // Bind the image service.
97
        $this->app->bind( ImageServiceInterface::class, function ( $app )
98
        {
99
            return $app->make( ImageService::class );
100
        });
101
    }
102
103
    /**
104
     *
105
     */
106
    private function loadHelpers()
107
    {
108
        foreach (glob(__DIR__.'/Helpers/*.php') as $filename) require_once( $filename );
109
    }
110
111
112
    /**
113
     *
114
     */
115
    private function registerPurgeImagesCommand()
116
    {
117
        $this->app->singleton('command.images.purge-deleted-images', function ($app)
118
        {
119
            return $app[ \OkayBueno\Images\Commands\PurgeDeletedImages::class ];
120
        });
121
122
        $this->commands('command.images.purge-deleted-images');
123
    }
124
125
    /**
126
     *
127
     */
128
    private function registerResizeImageCommand()
129
    {
130
        $this->app->singleton('command.images.resize-image', function ($app)
131
        {
132
            return $app[ \OkayBueno\Images\Commands\ResizeImage::class ];
133
        });
134
135
        $this->commands('command.images.resize-image');
136
    }
137
138
139
}