Completed
Push — master ( 6afef5...701ec0 )
by Dan Michael O.
16:21 queued 14:10
created

HttpClientProvider   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 5
dl 0
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 16 1
A provides() 0 7 1
1
<?php
2
3
namespace Colligator\Providers;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;
7
use Http\Client\HttpClient;
8
use Http\Message\MessageFactory;
9
use Http\Message\MessageFactory\GuzzleMessageFactory;
10
11
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
12
13
class HttpClientProvider extends ServiceProvider
14
{
15
    /**
16
     * Indicates if loading of the provider is deferred.
17
     *
18
     * @var bool
19
     */
20
    protected $defer = true;
21
22
    /**
23
     * Register the service provider.
24
     *
25
     * @return void
26
     */
27
    public function register()
28
    {
29
        $this->app->singleton(HttpClient::class, function () {
30
            $config = ['timeout' => 30];
31
            $client = new GuzzleClient($config);
32
            $adapter = new GuzzleAdapter($client);
33
34
            return $adapter;
35
        });
36
37
        $this->app->singleton(MessageFactory::class, function () {
38
            $factory = new GuzzleMessageFactory();
39
40
            return $factory;
41
        });
42
    }
43
44
    /**
45
     * Get the services provided by the provider.
46
     *
47
     * @return array
48
     */
49
    public function provides()
50
    {
51
        return [
52
            HttpClient::class,
53
            MessageFactory::class,
54
        ];
55
    }
56
}
57