Completed
Push — master ( 590036...4ee46d )
by Miguel
04:37 queued 02:19
created

FeatureServiceProvider::boot()   C

Complexity

Conditions 7
Paths 8

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 12
nc 8
nop 1
dl 0
loc 22
rs 6.9811
c 0
b 0
f 0
1
<?php
2
3
namespace M1guelpf\Feature;
4
5
use Illuminate\Support\ServiceProvider;
6
7
class FeatureServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * Bootstrap the application services.
11
     *
12
     * @param FeatureManager $feature
13
     *
14
     * @return void
15
     */
16
    public function boot(FeatureManager $feature)
17
    {
18
        if ($this->app->runningInConsole()) {
19
            $this->publishes([
20
                __DIR__.'/../config/features.php' => config_path('features.php'),
21
            ], 'config');
22
        }
23
24
        if (class_exists(\Illuminate\Routing\Route::class)) {
25
            \Illuminate\Routing\Route::macro('feature', function (string $name, string $function = '') use ($feature) {
26
                feature($name, empty(trim($function)) ? 'routes' : "routes.$function") ? null : $this->uses('\M1guelpf\Feature\FeatureDisabledController');
0 ignored issues
show
Bug introduced by
The method uses() does not seem to exist on object<M1guelpf\Feature\FeatureServiceProvider>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
28
                return $this;
29
            });
30
        }
31
32
        if (class_exists(\Illuminate\Support\Facades\Blade::class)) {
33
            \Illuminate\Support\Facades\Blade::if('feature', function (string $name, string $function = '') {
34
                return feature($name, empty(trim($function)) ? 'views' : "views.$function");
35
            });
36
        }
37
    }
38
39
    /**
40
     * Register the application services.
41
     */
42
    public function register()
43
    {
44
        $this->mergeConfigFrom(__DIR__.'/../config/features.php', 'feature');
45
46
        $this->app->singleton('feature', 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...
47
            return new FeatureManager(config('features') ?? []);
48
        });
49
50
        $this->app->alias('feature', FeatureManager::class);
51
    }
52
}
53