Test Failed
Push — main ( 706477...92dbda )
by Yaroslav
03:43
created

ServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 62.07%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 62
ccs 18
cts 29
cp 0.6207
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addMiddleware() 0 14 3
A register() 0 3 1
A boot() 0 21 2
1
<?php
2
3
namespace NovaFlexibleContent;
4
5
use Laravel\Nova\Events\ServingNova;
6
use Laravel\Nova\Nova;
7
use NovaFlexibleContent\Http\FlexibleAttribute;
8
use NovaFlexibleContent\Http\Middleware\InterceptFlexibleAttributes;
9
10
class ServiceProvider extends \Illuminate\Support\ServiceProvider
11
{
12
    /**
13
     * Bootstrap any application services.
14
     *
15
     * @return void
16
     */
17 29
    public function boot(): void
18
    {
19 29
        $this->addMiddleware();
20
21 29
        Nova::serving(function (ServingNova $event) {
0 ignored issues
show
Unused Code introduced by
The parameter $event is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

21
        Nova::serving(function (/** @scrutinizer ignore-unused */ ServingNova $event) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
22
            Nova::script('flexible-content-field', __DIR__ . '/../dist/js/field.js');
23
            Nova::style('flexible-content-field', __DIR__ . '/../dist/css/field.css');
24
25
            Nova::provideToScript([
26
                'flexible-content-field.flexible-attribute-key-name' => FlexibleAttribute::REGISTER_FLEXIBLE_FIELD_NAME,
27
                'flexible-content-field.file-indicator-prefix'       => FlexibleAttribute::FILE_INDICATOR,
28
                'flexible-content-field.group-separator'             => FlexibleAttribute::GROUP_SEPARATOR,
29
            ]);
30 29
        });
31
32 29
        if ($this->app->runningInConsole()) {
33 29
            $this->publishes([
34 29
                __DIR__ . '/../config/nova-flexible-content.php' => config_path('nova-flexible-content.php'),
35 29
            ], 'config');
36
37 29
            $this->commands([
38 29
                //
39 29
            ]);
40
        }
41
    }
42
43
    /**
44
     * Register any application services.
45
     *
46
     * @return void
47
     */
48 29
    public function register(): void
49
    {
50 29
        $this->mergeConfigFrom(__DIR__ . '/../config/nova-flexible-content.php', 'nova-flexible-content');
51
    }
52
53
    /**
54
     * Adds required middleware for Nova requests.
55
     *
56
     * @return void
57
     */
58 29
    public function addMiddleware(): void
59
    {
60 29
        $router = $this->app['router'];
61
62 29
        if ($router->hasMiddlewareGroup('nova')) {
63 29
            $router->pushMiddlewareToGroup('nova', InterceptFlexibleAttributes::class);
64
65 29
            return;
66
        }
67
68
        if (!$this->app->configurationIsCached()) {
69
            config()->set('nova.middleware', array_merge(
70
                config('nova.middleware', []),
71
                [InterceptFlexibleAttributes::class]
72
            ));
73
        }
74
    }
75
}
76