AbstractService   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 2
A getRequest() 0 7 1
A addGetParameters() 0 5 2
1
<?php
2
3
namespace PagaMasTarde\Service;
4
5
use Httpful\Mime;
6
use Httpful\Request;
7
8
/**
9
 * Class AbstractService
10
 * @package PagaMasTarde\Service
11
 */
12
abstract class AbstractService
13
{
14
    /**
15
     * BASE API URI
16
     */
17
    const BASE_URI = 'https://api.pagantis.com';
18
19
    /**
20
     * Private key for API calls
21
     *
22
     * @var string
23
     */
24
    protected $privateKey;
25
26
    /**
27
     * @var string
28
     */
29
    protected $baseUri;
30
31
    /**
32
     * @var Request
33
     */
34
    protected $request;
35
36
    /**
37
     * AbstractService constructor.
38
     *
39
     * @param string $privateKey
40
     * @param null   $baseUri
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $baseUri is correct as it would always require null to be passed?
Loading history...
41
     */
42
    public function __construct($privateKey, $baseUri = null)
43
    {
44
        $this->privateKey = $privateKey;
45
        $this->baseUri = $baseUri === null ? self::BASE_URI : $baseUri;
46
    }
47
48
    /**
49
     * @return Request
50
     */
51
    protected function getRequest()
52
    {
53
        return Request::init()
54
            ->sendsType(Mime::JSON)
55
            ->addHeader('Authorization', 'Bearer ' . $this->privateKey)
56
            ->expects(Mime::JSON)
57
            ->timeoutIn(2)
58
        ;
59
    }
60
61
    /**
62
     * @param $array
63
     *
64
     * @return string
65
     */
66
    protected function addGetParameters($array)
67
    {
68
        $query = http_build_query(array_filter($array));
69
70
        return empty($query) ? '' : '?' . $query;
71
    }
72
}
73