Completed
Push — master ( ae1c3d...eb4059 )
by Sébastien
10:48
created

VivaPaymentsServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 6
eloc 15
c 2
b 0
f 0
dl 0
loc 64
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A provides() 0 3 1
A curlDoesntUseNss() 0 5 1
A register() 0 11 1
A isDeferred() 0 3 1
A buildGuzzleClient() 0 6 2
1
<?php
2
3
namespace Sebdesign\VivaPayments;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use Illuminate\Support\ServiceProvider;
7
8
class VivaPaymentsServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * Register the application services.
12
     *
13
     * @return void
14
     */
15
    public function register()
16
    {
17
        $this->mergeConfigFrom(
18
            __DIR__.'/../config/services.php',
19
            'services'
20
        );
21
22
        $this->app->singleton(Client::class, function ($app) {
23
            return new Client(
24
                $this->buildGuzzleClient(),
25
                $app->make('config')->get('services.viva.environment')
26
            );
27
        });
28
    }
29
30
    /**
31
     * Build the Guzzlehttp client.
32
     */
33
    protected function buildGuzzleClient(): GuzzleClient
34
    {
35
        return new GuzzleClient([
36
            'curl' => $this->curlDoesntUseNss()
37
                ? [CURLOPT_SSL_CIPHER_LIST => 'TLSv1']
38
                : [],
39
        ]);
40
    }
41
42
    /**
43
     * Check if cURL doens't use NSS.
44
     *
45
     * @return bool
46
     */
47
    protected function curlDoesntUseNss()
48
    {
49
        $curl = curl_version();
50
51
        return ! preg_match('/NSS/', $curl['ssl_version']);
52
    }
53
54
    /**
55
     * Determine if the provider is deferred.
56
     *
57
     * @return bool
58
     */
59
    public function isDeferred()
60
    {
61
        return true;
62
    }
63
64
    /**
65
     * Get the services provided by the provider.
66
     *
67
     * @return array
68
     */
69
    public function provides()
70
    {
71
        return [Client::class];
72
    }
73
}
74