Client::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 4
nop 3
dl 0
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Rinvex\Authy;
6
7
use GuzzleHttp\ClientInterface;
8
9
class Client
10
{
11
    /**
12
     * The HTTP client instance.
13
     *
14
     * @var \GuzzleHttp\ClientInterface
15
     */
16
    protected $http;
17
18
    /**
19
     * The HTTP client parameters.
20
     *
21
     * @var array
22
     */
23
    protected $params;
24
25
    /**
26
     * The Authy service API endpoint.
27
     *
28
     * @var string
29
     */
30
    protected $api;
31
32
    /**
33
     * Create a new Authy client instance.
34
     *
35
     * @param \GuzzleHttp\ClientInterface $client
36
     * @param string                      $key
37
     * @param string                      $format
38
     *
39
     * @throws \Rinvex\Authy\InvalidConfiguration
40
     */
41
    public function __construct(ClientInterface $client, $key, $format = 'json')
42
    {
43
        // Prepare required data
44
        $this->http = $client;
45
        $format = $format === 'xml' ? 'xml' : 'json';
46
        $this->params = ['http_errors' => false, 'headers' => ['X-Authy-API-Key' => $key]];
47
        $this->api = "https://api.authy.com/protected/{$format}/";
48
49
        // Check configuration
50
        if (! $key) {
51
            throw InvalidConfiguration::missingCredentials();
52
        }
53
    }
54
}
55