EtagConditionalsServiceProvider::provides()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Werk365\EtagConditionals;
4
5
use Illuminate\Support\ServiceProvider;
6
use Werk365\EtagConditionals\Middleware\IfMatch;
7
use Werk365\EtagConditionals\Middleware\IfNoneMatch;
8
use Werk365\EtagConditionals\Middleware\SetEtag;
9
10
class EtagConditionalsServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Perform post-registration booting of services.
14
     *
15
     * @return void
16
     */
17
    public function boot(): void
18
    {
19
        //Middlewares
20
        $middlewares = [
21
            SetEtag::class,
22
            IfNoneMatch::class,
23
            IfMatch::class,
24
        ];
25
26
        // Set middleware group
27
        $this->app['router']->middlewareGroup('etag', $middlewares);
28
29
        // Set individual middlewares
30
        foreach ($middlewares as $middleware) {
31
            $this->app['router']->aliasMiddleware((new $middleware)->name(), $middleware);
32
        }
33
34
        // Publishing is only necessary when using the CLI.
35
        if ($this->app->runningInConsole()) {
36
            $this->bootForConsole();
37
        }
38
    }
39
40
    /**
41
     * Register any package services.
42
     *
43
     * @return void
44
     */
45
    public function register(): void
46
    {
47
        $this->mergeConfigFrom(__DIR__.'/../config/etagconditionals.php', 'etagconditionals');
48
49
        // Register the service the package provides.
50
        $this->app->singleton('etagconditionals', function ($app) {
0 ignored issues
show
Unused Code introduced by
The parameter $app 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

50
        $this->app->singleton('etagconditionals', function (/** @scrutinizer ignore-unused */ $app) {

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...
51
            return new EtagConditionals;
52
        });
53
    }
54
55
    /**
56
     * Get the services provided by the provider.
57
     *
58
     * @return array
59
     */
60
    public function provides()
61
    {
62
        return ['etagconditionals'];
63
    }
64
65
    /**
66
     * Console-specific booting.
67
     *
68
     * @return void
69
     */
70
    protected function bootForConsole(): void
71
    {
72
        // Publishing the configuration file.
73
        $this->publishes([
74
            __DIR__.'/../config/etagconditionals.php' => config_path('etagconditionals.php'),
75
        ], 'etagconditionals.config');
76
    }
77
}
78