Completed
Push — master ( 4eaaa2...06a8e1 )
by
unknown
10s
created

PrestasiServiceProvider::publishHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Bantenprov\Prestasi;
4
5
use Illuminate\Support\ServiceProvider;
6
use Bantenprov\Prestasi\Console\Commands\PrestasiCommand;
7
8
/**
9
 * The PrestasiServiceProvider class
10
 *
11
 * @package Bantenprov\Prestasi
12
 * @author  bantenprov <[email protected]>
13
 */
14
class PrestasiServiceProvider 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('prestasi', 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 Prestasi;
50
        });
51
52
        $this->app->singleton('command.prestasi', 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 PrestasiCommand;
54
        });
55
56
        $this->commands('command.prestasi');
57
    }
58
59
    /**
60
     * Get the services provided by the provider.
61
     *
62
     * @return array
63
     */
64
    public function provides()
65
    {
66
        return [
67
            'prestasi',
68
            'command.prestasi',
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/prestasi');
81
82
        $this->mergeConfigFrom($packageConfigPath.'/prestasi.php', 'prestasi');
83
        $this->mergeConfigFrom($packageConfigPath.'/master-prestasi.php', 'master-prestasi');
84
        $this->mergeConfigFrom($packageConfigPath.'/jenis-prestasi.php', 'jenis-prestasi');
85
86
        $this->publishes([
87
            $packageConfigPath.'/prestasi.php' => $appConfigPath.'/prestasi.php',
88
            $packageConfigPath.'/master-prestasi.php' => $appConfigPath.'/master-prestasi.php',
89
            $packageConfigPath.'/jenis-prestasi.php' => $appConfigPath.'/jenis-prestasi.php',
90
        ], $publish ? $publish : 'prestasi-config');
91
    }
92
93
    /**
94
     * Loading package routes
95
     *
96
     * @return void
97
     */
98
    protected function routeHandle()
99
    {
100
        $this->loadRoutesFrom(__DIR__.'/routes/routes.php');
101
    }
102
103
    /**
104
     * Loading and publishing package's translations
105
     *
106
     * @return void
107
     */
108 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...
109
    {
110
        $packageTranslationsPath = __DIR__.'/resources/lang';
111
112
        $this->loadTranslationsFrom($packageTranslationsPath, 'prestasi');
113
114
        $this->publishes([
115
            $packageTranslationsPath => resource_path('lang/vendor/prestasi'),
116
        ], $publish ? $publish : 'prestasi-lang');
117
    }
118
119
    /**
120
     * Loading and publishing package's views
121
     *
122
     * @return void
123
     */
124 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...
125
    {
126
        $packageViewsPath = __DIR__.'/resources/views';
127
128
        $this->loadViewsFrom($packageViewsPath, 'prestasi');
129
130
        $this->publishes([
131
            $packageViewsPath => resource_path('views/vendor/prestasi'),
132
        ], $publish ? $publish : 'prestasi-views');
133
    }
134
135
    /**
136
     * Publishing package's assets (JavaScript, CSS, images...)
137
     *
138
     * @return void
139
     */
140
    protected function assetHandle($publish = '')
141
    {
142
        $packageAssetsPath = __DIR__.'/resources/assets';
143
144
        $this->publishes([
145
            $packageAssetsPath => resource_path('assets'),
146
        ], $publish ? $publish : 'prestasi-assets');
147
    }
148
149
    /**
150
     * Publishing package's migrations
151
     *
152
     * @return void
153
     */
154
    protected function migrationHandle($publish = '')
155
    {
156
        $packageMigrationsPath = __DIR__.'/database/migrations';
157
158
        $this->loadMigrationsFrom($packageMigrationsPath);
159
160
        $this->publishes([
161
            $packageMigrationsPath => database_path('migrations')
162
        ], $publish ? $publish : 'prestasi-migrations');
163
    }
164
165
    /**
166
     * Publishing package's publics (JavaScript, CSS, images...)
167
     *
168
     * @return void
169
     */
170
    public function publicHandle($publish = '')
171
    {
172
        $packagePublicPath = __DIR__.'/public';
173
174
        $this->publishes([
175
            $packagePublicPath => base_path('public')
176
        ], $publish ? $publish : 'prestasi-public');
177
    }
178
179
    /**
180
     * Publishing package's seeds
181
     *
182
     * @return void
183
     */
184
    public function seedHandle($publish = '')
185
    {
186
        $packageSeedPath = __DIR__.'/database/seeds';
187
188
        $this->publishes([
189
            $packageSeedPath => base_path('database/seeds')
190
        ], $publish ? $publish : 'prestasi-seeds');
191
    }
192
193
    /**
194
     * Publishing package's all files
195
     *
196
     * @return void
197
     */
198
    public function publishHandle()
199
    {
200
        $publish = 'prestasi-publish';
201
202
        $this->routeHandle($publish);
0 ignored issues
show
Unused Code introduced by
The call to PrestasiServiceProvider::routeHandle() has too many arguments starting with $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...
203
        $this->configHandle($publish);
204
        $this->langHandle($publish);
205
        $this->viewHandle($publish);
206
        $this->assetHandle($publish);
207
        // $this->migrationHandle($publish);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
208
        $this->publicHandle($publish);
209
        $this->seedHandle($publish);
210
    }
211
}
212