Completed
Push — master ( 2c722f...4f3f82 )
by Maxime
20:28
created

ExpendableServiceProvider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 12

Test Coverage

Coverage 98.63%

Importance

Changes 14
Bugs 2 Features 6
Metric Value
wmc 9
c 14
b 2
f 6
lcom 2
cbo 12
dl 0
loc 144
ccs 72
cts 73
cp 0.9863
rs 10

7 Methods

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