Connection::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 6
Bugs 0 Features 0
Metric Value
c 6
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 2
eloc 2
nc 2
nop 3
crap 2
1
<?php
2
3
namespace PHPushbullet;
4
5
use GuzzleHttp\Client;
6
7
class Connection
8
{
9
    /**
10
     * The base url for the Pushbullet API
11
     *
12
     * @var string $base_url
13
     */
14
    protected $base_url = 'https://api.pushbullet.com/v2/';
15
16
17
    /**
18
     * The pre-configured Guzzle client
19
     *
20
     * @var \GuzzleHttp\Client
21
     */
22
    protected $client;
23
24 27
    public function __construct($access_token, Client $client = null, array $config = [])
25
    {
26 27
        $this->client = $client ?: new Client($this->getClientParams($access_token, $config));
27 27
    }
28
29
    /**
30
     * @return \GuzzleHttp\Client
31
     */
32 27
    public function client()
33
    {
34 27
        return $this->client;
35
    }
36
37
    protected function getClientParams($access_token, array $config = [])
38
    {
39
        $headers = [
40
            'Access-Token' => $access_token,
41
            'Content-Type' => 'application/json',
42
        ];
43
44
        $config = array_merge(compact('headers'), $config);
45
46
        if (version_compare(Client::VERSION, 6, '>=')) {
47
            return array_merge([
48
                'base_uri' => $this->base_url,
49
            ], $config);
50
        }
51
52
        return [
53
            'base_url' => [$this->base_url, []],
54
            'defaults' => $config,
55
        ];
56
    }
57
}
58