Completed
Push — master ( ae1877...f4c876 )
by Maxime
128:48 queued 121:52
created

ExpendableServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 147
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 11

Test Coverage

Coverage 95.92%

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 11
dl 0
loc 147
ccs 47
cts 49
cp 0.9592
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A registerImporters() 0 17 1
B boot() 0 25 1
A registerCommands() 0 13 3
A provides() 0 15 1
A alias() 0 8 1
B register() 0 26 1
A registerExporters() 0 14 1
1
<?php namespace Distilleries\Expendable;
2
3
use Distilleries\Expendable\Exporter\CsvExporter;
4
use Distilleries\Expendable\Exporter\ExcelExporter;
5
use Distilleries\Expendable\Exporter\PdfExporter;
6
use Distilleries\Expendable\Importer\CsvImporter;
7
use Distilleries\Expendable\Importer\XlsImporter;
8
use Distilleries\Expendable\Layouts\LayoutManager;
9
use Distilleries\Expendable\Models\User;
10
use Distilleries\Expendable\States\StateDisplayer;
11
use Illuminate\Support\ServiceProvider;
12
use Illuminate\Foundation\AliasLoader;
13
14
class ExpendableServiceProvider extends ServiceProvider {
15
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = true;
22
23
    /**
24
     * Bootstrap the application events.
25
     *
26
     * @return void
27
     */
28 584
    public function boot()
29
    {
30
31 584
        $this->loadViewsFrom(__DIR__ . '/../../views', 'expendable');
32 584
        $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'expendable');
33 584
        $this->loadMigrationsFrom(__DIR__ . '/../../database/migrations/');
34
35
36 584
        $this->publishes([
37 584
            __DIR__ . '/../../config/config.php'    => config_path('expendable.php'),
38 584
            __DIR__ . '/../../database/seeds/'      => base_path('/database/seeds'),
39
        ]);
40
41
42 584
        $this->publishes([
43 584
            __DIR__ . '/../../views' => base_path('resources/views/vendor/expendable'),
44 584
        ], 'views');
45 584
        $this->mergeConfigFrom(
46 584
            __DIR__ . '/../../config/config.php', 'expendable'
47
        );
48
49 584
        $autoLoaderListener = new \Distilleries\Expendable\Register\ListenerAutoLoader(config('expendable.listener'));
50 584
        $autoLoaderListener->load();
51
52
    }
53
54
    /**
55
     * Register the service provider.
56
     *
57
     * @return void
58
     */
59 584
    public function register()
60
    {
61
62
               
63
        $this->app->singleton('Distilleries\Expendable\Contracts\LockableContract', 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...
64
        {
65 8
            return new User;
66 584
        });
67
68
        $this->app->singleton('Distilleries\Expendable\Contracts\StateDisplayerContract', function($app)
69
        {
70 288
            return new StateDisplayer($app['view'], $app['config']->get('expendable'));
71 584
        });
72
73
        $this->app->singleton('Distilleries\Expendable\Contracts\LayoutManagerContract', function($app)
74
        {
75 284
            return new LayoutManager($app['config']->get('expendable'), $app['view'], $app['files'], app('Distilleries\Expendable\Contracts\StateDisplayerContract'));
76 584
        });
77
78 584
        $this->alias();
79 584
        $this->registerCommands();
80 584
        $this->registerImporters();
81 584
        $this->registerExporters();
82
83
84
    }
85
    
86
87 584
    protected function registerImporters()
88
    {
89
        $this->app->singleton('CsvImporterContract', function()
90
        {
91 4
            return new CsvImporter;
92 584
        });
93
94
        $this->app->singleton('XlsImporterContract', function()
95
        {
96 4
            return new XlsImporter;
97 584
        });
98
99
        $this->app->singleton('XlsxImporterContract', function()
100
        {
101
            return new XlsImporter;
102 584
        });
103
    }
104
105 584
    protected function registerExporters()
106
    {
107
108
        $this->app->singleton('Distilleries\Expendable\Contracts\CsvExporterContract', function()
109
        {
110 4
            return new CsvExporter;
111 584
        });
112
        $this->app->singleton('Distilleries\Expendable\Contracts\ExcelExporterContract', function()
113
        {
114
            return new ExcelExporter;
115 584
        });
116
117
118
    }
119
120
121 584
    protected function registerCommands()
122
    {
123 584
        $file  = app('files');
124 584
        $files = $file->allFiles(__DIR__ . '/Console/');
125
126 584
        foreach ($files as $file)
127
        {
128 584
            if (strpos($file->getPathName(), 'Lib') === false)
129
            {
130 584
                $this->commands('Distilleries\Expendable\Console\\' . preg_replace('/\.php/i', '', $file->getFilename()));
131
            }
132
        }
133
    }
134
135 40
    public function provides()
136
    {
137
        return [
138 40
            'Distilleries\Expendable\Contracts\StateDisplayerContract',
139
            'Distilleries\Expendable\Contracts\LayoutManagerContract',
140
            'Distilleries\MailerSaver\Contracts\MailModelContract',
141
            'CsvImporterContract',
142
            'XlsImporterContract',
143
            'XlsxImporterContract',
144
            'Distilleries\Expendable\Contracts\CsvExporterContract',
145
            'Distilleries\Expendable\Contracts\ExcelExporterContract',
146
            'Distilleries\Expendable\Contracts\PdfExporterContract',
147
            'Distilleries\Expendable\Contracts\PdfExporterContract',
148
        ];
149
    }
150
151
152 584
    public function alias()
153
    {
154
155 584
        AliasLoader::getInstance()->alias(
156 584
            'Excel',
157 584
            'Maatwebsite\Excel\Facades\Excel'
158
        );
159
    }
160
}