FeatureServiceProvider   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 46
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
B boot() 0 22 7
A register() 0 10 1
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