Xotelia   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 25 1
A bookings() 0 4 1
1
<?php
2
3
namespace XoteliaClient;
4
5
use GuzzleHttp\Client as GuzzleClient;
6
use GuzzleHttp\Subscriber\Retry\RetrySubscriber;
7
use XoteliaClient\Endpoint\Booking;
8
9
class Xotelia
10
{
11
    const BASE_URL = 'https://admin.xotelia.com/api/';
12
    const MAX_RETRIES = 5;
13
14
    /**
15
     * @var Client
16
     */
17
    protected $client;
18
19
    /**
20
     * @param string $token
21
     * @param int $maxRetries
22
     */
23
    public function __construct($token, $maxRetries = self::MAX_RETRIES)
24
    {
25
        $handler = new GuzzleClient([
26
            'base_url' => self::BASE_URL,
27
            'defaults' => [
28
                'headers' => [
29
                    'Content-Type'  => 'application/json',
30
                    'Accept'        => 'application/json',
31
                    'Authorization' => sprintf('Bearer %s', $token),
32
                ],
33
            ],
34
        ]);
35
36
        $retry = new RetrySubscriber([
37
            'filter' => RetrySubscriber::createChainFilter([
38
                RetrySubscriber::createCurlFilter([CURLE_PARTIAL_FILE]),
39
                RetrySubscriber::createStatusFilter([500, 502, 503, 504]),
40
            ]),
41
            'max'    => $maxRetries,
42
        ]);
43
44
        $handler->getEmitter()->attach($retry);
45
46
        $this->client = new Client($handler);
47
    }
48
49
    /**
50
     * @return Booking
51
     */
52
    public function bookings()
53
    {
54
        return new Booking($this->client);
55
    }
56
}
57