Passed
Push — develop ( 6e78c9...4aabf2 )
by Stan
04:01 queued 22s
created

Http2PusherServiceProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 59
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 5 1
A register() 0 7 1
A registerResponse() 0 4 1
A registerBuilder() 0 6 1
1
<?php
2
3
namespace Krenor\Http2Pusher\Providers;
4
5
use Krenor\Http2Pusher\Builder;
6
use Illuminate\Support\ServiceProvider;
7
use Krenor\Http2Pusher\Factories\ResponseFactory;
8
use Illuminate\Contracts\View\Factory as ViewFactoryContract;
9
use Illuminate\Contracts\Routing\ResponseFactory as ResponseFactoryContract;
10
11
class Http2PusherServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Path to the default configuration file.
15
     *
16
     * @var string
17
     */
18
    private $config = __DIR__ . '/../config/http2-pusher.php';
19
20
    /**
21
     * Bootstrap any application services.
22
     *
23
     * @return void
24
     */
25
    public function boot()
26
    {
27
        $this->publishes([
28
            $this->config => config_path('http2-pusher.php'),
1 ignored issue
show
Bug introduced by
The function config_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

28
            $this->config => /** @scrutinizer ignore-call */ config_path('http2-pusher.php'),
Loading history...
29
        ], 'config');
30
    }
31
32
    /**
33
     * Register bindings in the container.
34
     *
35
     * @return void
36
     */
37
    public function register()
38
    {
39
        $this->mergeConfigFrom($this->config, 'http2-pusher');
40
41
        $this->registerBuilder();
42
43
        $this->registerResponse();
44
    }
45
46
    /**
47
     * Register the builder for HTTP2 pushes.
48
     *
49
     * @return void
50
     */
51
    private function registerBuilder()
52
    {
53
        $this->app->singleton(Builder::class, function ($app) {
54
            return new Builder(
55
                $app['request'],
56
                $app['config']['http2-pusher']
57
            );
58
        });
59
    }
60
61
    /**
62
     * Override the response factory provided by Laravel.
63
     *
64
     * @return void
65
     */
66
    private function registerResponse()
67
    {
68
        $this->app->singleton(ResponseFactoryContract::class, function ($app) {
69
            return new ResponseFactory($app[ViewFactoryContract::class], $app['redirect']);
70
        });
71
    }
72
}
73