Connection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 29.4%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 5
c 8
b 0
f 0
lcom 1
cbo 1
dl 0
loc 51
ccs 5
cts 17
cp 0.294
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A client() 0 4 1
A getClientParams() 0 20 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