HttpServiceProvider   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A register() 0 4 1
A registerGuzzle() 0 20 1
1
<?php
2
3
namespace Magister\Services\Http;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Subscriber\Cache\CacheSubscriber;
7
use Magister\Services\Support\ServiceProvider;
8
9
/**
10
 * Class HttpServiceProvider.
11
 */
12
class HttpServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * Register bindings in the container.
16
     *
17
     * @return void
18
     */
19
    public function register()
20
    {
21
        $this->registerGuzzle();
22
    }
23
24
    /**
25
     * Register the Guzzle driver.
26
     *
27
     * @return void
28
     */
29
    protected function registerGuzzle()
30
    {
31
        $this->app->singleton('http', function ($app) {
32
            $client = new Client([
33
                'base_url' => "https://{$app['school']}.magister.net/api/",
34
            ]);
35
36
            $client->setDefaultOption('exceptions', false);
37
38
            $client->setDefaultOption('cookies', new SessionCookieJar($app['cookie']));
39
40
            $client->setDefaultOption('headers', [
41
                'X-API-Client-ID' => env('MAGISTER_API_KEY', '12D8'),
42
            ]);
43
44
            CacheSubscriber::attach($client);
45
46
            return $client;
47
        });
48
    }
49
}
50