Completed
Push — master ( 2d4ad9...f01300 )
by
unknown
9s
created

NilaiServiceProvider::publishHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Bantenprov\Nilai;
4
5
use Illuminate\Support\ServiceProvider;
6
use Bantenprov\Nilai\Console\Commands\NilaiCommand;
7
8
/**
9
 * The NilaiServiceProvider class
10
 *
11
 * @package Bantenprov\Nilai
12
 * @author  bantenprov <[email protected]>
13
 */
14
class NilaiServiceProvider extends ServiceProvider
15
{
16
    /**
17
     * Indicates if loading of the provider is deferred.
18
     *
19
     * @var bool
20
     */
21
    protected $defer = false;
22
23
    /**
24
     * Bootstrap the application events.
25
     *
26
     * @return void
27
     */
28
    public function boot()
29
    {
30
        $this->routeHandle();
31
        $this->configHandle();
32
        $this->langHandle();
33
        $this->viewHandle();
34
        $this->assetHandle();
35
        $this->migrationHandle();
36
        $this->publicHandle();
37
        $this->seedHandle();
38
        $this->publishHandle();
39
    }
40
41
    /**
42
     * Register the service provider.
43
     *
44
     * @return void
45
     */
46
    public function register()
47
    {
48
        $this->app->singleton('nilai', 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...
49
            return new Nilai;
50
        });
51
52
        $this->app->singleton('command.nilai', 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...
53
            return new NilaiCommand;
54
        });
55
56
        $this->commands('command.nilai');
57
    }
58
59
    /**
60
     * Get the services provided by the provider.
61
     *
62
     * @return array
63
     */
64
    public function provides()
65
    {
66
        return [
67
            'nilai',
68
            'command.nilai',
69
        ];
70
    }
71
72
    /**
73
     * Loading and publishing package's config
74
     *
75
     * @return void
76
     */
77
    protected function configHandle($publish='')
78
    {
79
        $packageConfigPath = __DIR__.'/config';
80
        $appConfigPath     = config_path('bantenprov/nilai');
81
82
        $this->mergeConfigFrom($packageConfigPath.'/nilai.php', 'nilai');
83
        $this->mergeConfigFrom($packageConfigPath.'/akademik.php', 'akademik');
84
85
        $this->publishes([
86
            $packageConfigPath.'/nilai.php' => $appConfigPath.'/nilai.php',
87
            $packageConfigPath.'/akademik.php' => $appConfigPath.'/akademik.php',
88
        ], $publish ? $publish : 'nilai-config');
89
    }
90
91
    /**
92
     * Loading package routes
93
     *
94
     * @return void
95
     */
96
    protected function routeHandle()
97
    {
98
        $this->loadRoutesFrom(__DIR__.'/routes/routes.php');
99
    }
100
101
    /**
102
     * Loading and publishing package's translations
103
     *
104
     * @return void
105
     */
106 View Code Duplication
    protected function langHandle($publish='')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
107
    {
108
        $packageTranslationsPath = __DIR__.'/resources/lang';
109
110
        $this->loadTranslationsFrom($packageTranslationsPath, 'nilai');
111
112
        $this->publishes([
113
            $packageTranslationsPath => resource_path('lang/vendor/nilai'),
114
        ], $publish ? $publish : 'nilai-lang');
115
    }
116
117
    /**
118
     * Loading and publishing package's views
119
     *
120
     * @return void
121
     */
122 View Code Duplication
    protected function viewHandle($publish='')
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
123
    {
124
        $packageViewsPath = __DIR__.'/resources/views';
125
126
        $this->loadViewsFrom($packageViewsPath, 'nilai');
127
128
        $this->publishes([
129
            $packageViewsPath => resource_path('views/vendor/nilai'),
130
        ], $publish ? $publish : 'nilai-views');
131
    }
132
133
    /**
134
     * Publishing package's assets (JavaScript, CSS, images...)
135
     *
136
     * @return void
137
     */
138
    protected function assetHandle($publish='')
139
    {
140
        $packageAssetsPath = __DIR__.'/resources/assets';
141
142
        $this->publishes([
143
            $packageAssetsPath => resource_path('assets'),
144
        ], $publish ? $publish : 'nilai-assets');
145
    }
146
147
    /**
148
     * Publishing package's migrations
149
     *
150
     * @return void
151
     */
152
    protected function migrationHandle($publish='')
153
    {
154
        $packageMigrationsPath = __DIR__.'/database/migrations';
155
156
        $this->loadMigrationsFrom($packageMigrationsPath);
157
158
        $this->publishes([
159
            $packageMigrationsPath => database_path('migrations')
160
        ], $publish ? $publish : 'nilai-migrations');
161
    }
162
163
    public function publicHandle($publish='')
164
    {
165
        $packagePublicPath = __DIR__.'/public';
166
167
        $this->publishes([
168
            $packagePublicPath => base_path('public')
169
        ], $publish ? $publish : 'nilai-public');
170
    }
171
172
    public function seedHandle($publish='')
173
    {
174
        $packageSeedPath = __DIR__.'/database/seeds';
175
176
        $this->publishes([
177
            $packageSeedPath => base_path('database/seeds')
178
        ], $publish ? $publish : 'nilai-seeds');
179
    }
180
181
    public function publishHandle()
182
    {
183
        $this->routeHandle('nilai-publish');
0 ignored issues
show
Unused Code introduced by
The call to NilaiServiceProvider::routeHandle() has too many arguments starting with 'nilai-publish'.

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...
184
        $this->configHandle('nilai-publish');
185
        $this->langHandle('nilai-publish');
186
        $this->viewHandle('nilai-publish');
187
        $this->assetHandle('nilai-publish');
188
        $this->migrationHandle('nilai-publish');
189
        $this->publicHandle('nilai-publish');
190
        $this->seedHandle('nilai-publish');
191
    }
192
}
193