Completed
Push — master ( 0d5f52...0e93a7 )
by Maxime
30:53 queued 07:15
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.61%

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 71
cts 72
cp 0.9861
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
A alias() 0 8 1
B register() 0 30 1
A registerImporters() 0 17 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 672
    public function boot()
30
    {
31 672
        $this->loadViewsFrom(__DIR__ . '/../../views', 'expendable');
32 672
        $this->loadTranslationsFrom(__DIR__ . '/../../lang', 'expendable');
33 672
        $this->publishes([
34 672
            __DIR__ . '/../../config/config.php'    => config_path('expendable.php'),
35 672
            __DIR__ . '/../../database/migrations/' => base_path('/database/migrations'),
36 672
            __DIR__ . '/../../database/seeds/'      => base_path('/database/seeds'),
37 672
        ]);
38 672
        $this->publishes([
39 672
            __DIR__ . '/../../views' => base_path('resources/views/vendor/expendable'),
40 672
        ], 'views');
41 672
        $this->mergeConfigFrom(
42 672
            __DIR__ . '/../../config/config.php', 'expendable'
43 672
        );
44
45 672
        $autoLoaderListener = new \Distilleries\Expendable\Register\ListenerAutoLoader(config('expendable.listener'));
46 672
        $autoLoaderListener->load();
47
48 672
    }
49
50
    /**
51
     * Register the service provider.
52
     *
53
     * @return void
54
     */
55 672
    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 672
        });
62
63
        $this->app->singleton('Distilleries\Expendable\Contracts\StateDisplayerContract', function($app)
64
        {
65 672
            return new StateDisplayer($app['view'], $app['config']->get('expendable'));
66 672
        });
67
68
        $this->app->singleton('Distilleries\Expendable\Contracts\LayoutManagerContract', function($app)
69
        {
70 312
            return new LayoutManager($app['config']->get('expendable'), $app['view'], $app['files'], app('Distilleries\Expendable\Contracts\StateDisplayerContract'));
71 672
        });
72
73
        $this->app->singleton('Distilleries\MailerSaver\Contracts\MailModelContract', function()
74
        {
75 52
            return new Email;
76 672
        });
77
78 672
        $this->alias();
79 672
        $this->registerCommands();
80 672
        $this->registerImporters();
81 672
        $this->registerExporters();
82
83
84 672
    }
85
86 672
    protected function registerImporters()
87
    {
88
        $this->app->singleton('CsvImporterContract', function()
89
        {
90 4
            return new CsvImporter;
91 672
        });
92
93
        $this->app->singleton('XlsImporterContract', function()
94
        {
95 672
            return new XlsImporter;
96 672
        });
97
98
        $this->app->singleton('XlsxImporterContract', function()
99
        {
100
            return new XlsImporter;
101 672
        });
102 672
    }
103
104 672
    protected function registerExporters()
105
    {
106
107
        $this->app->singleton('Distilleries\Expendable\Contracts\CsvExporterContract', function()
108
        {
109 4
            return new CsvExporter;
110 672
        });
111 672
        $this->app->singleton('Distilleries\Expendable\Contracts\ExcelExporterContract', function()
112
        {
113 4
            return new ExcelExporter;
114 672
        });
115
116
117 672
    }
118
119
120 672
    protected function registerCommands()
121
    {
122 672
        $file  = app('files');
123 672
        $files = $file->allFiles(__DIR__ . '/Console/');
124
125 672
        foreach ($files as $file)
126
        {
127 672
            if (strpos($file->getPathName(), 'Lib') === false)
128 672
            {
129 672
                $this->commands('Distilleries\Expendable\Console\\' . preg_replace('/\.php/i', '', $file->getFilename()));
130 672
            }
131 672
        }
132 672
    }
133
134 44
    public function provides()
135
    {
136
        return [
137 44
            'Distilleries\Expendable\Contracts\StateDisplayerContract',
138 44
            'Distilleries\Expendable\Contracts\LayoutManagerContract',
139 44
            'Distilleries\MailerSaver\Contracts\MailModelContract',
140 44
            'CsvImporterContract',
141 44
            'XlsImporterContract',
142 44
            'XlsxImporterContract',
143 44
            'Distilleries\Expendable\Contracts\CsvExporterContract',
144 44
            'Distilleries\Expendable\Contracts\ExcelExporterContract',
145 44
            'Distilleries\Expendable\Contracts\PdfExporterContract',
146 44
        ];
147
    }
148
149
150 672
    public function alias()
151
    {
152
153 672
        AliasLoader::getInstance()->alias(
154 672
            'Excel',
155
            'Maatwebsite\Excel\Facades\Excel'
156 672
        );
157
    }
158
}