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

VivaPaymentsServiceProvider::isDeferred()   A

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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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