GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( bc3c30...d86446 )
by Samuel
04:01
created

Service   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 6
Bugs 0 Features 2
Metric Value
wmc 11
c 6
b 0
f 2
lcom 2
cbo 0
dl 0
loc 88
ccs 0
cts 49
cp 0
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A setLanguage() 0 4 1
A setHeader() 0 5 1
A hasParameter() 0 4 1
A setParameter() 0 5 1
A getParameter() 0 5 2
A getBaseUrl() 0 4 1
buildRequest() 0 1 ?
A send() 0 15 1
A applyHeaders() 0 6 2
1
<?php
2
namespace LinusShops\CanadaPost;
3
4
use Guzzle\Http\Message\RequestInterface;
5
use Guzzle\Http\Message\Response;
6
7
8
/**
9
 *
10
 *
11
 * @author Sam Schmidt <[email protected]>
12
 * @since 2015-12-09
13
 * @company Linus Shops
14
 */
15
abstract class Service
16
{
17
    const HTTP_GET = 'GET';
18
    const HTTP_POST = 'POST';
19
    const HTTP_PUT = 'PUT';
20
    const HTTP_DELETE = 'DELETE';
21
    const HTTP_PATCH = 'PATCH';
22
23
    protected $baseUrl;
24
    protected $userid;
25
    protected $password;
26
    protected $parameters = array();
27
    protected $headers = array();
28
29
    public function __construct($baseUrl, $userid, $password)
30
    {
31
        $this->baseUrl = $baseUrl;
32
        $this->userid = $userid;
33
        $this->password = $password;
34
    }
35
36
    public function setLanguage($value)
37
    {
38
        $this->setHeader('Accept-language', $value);
39
    }
40
41
    public function setHeader($name, $value)
42
    {
43
        $this->headers[$name] = $value;
44
        return $this;
45
    }
46
47
    public function hasParameter($name)
48
    {
49
        return isset($this->parameters[$name]);
50
    }
51
52
    public function setParameter($name, $value)
53
    {
54
        $this->parameters[$name] = $value;
55
        return $this;
56
    }
57
58
    public function getParameter($name, $default=null)
59
    {
60
        return $this->hasParameter($name) ?
61
            $this->parameters[$name] : $default;
62
    }
63
64
    public function getBaseUrl()
65
    {
66
        return $this->baseUrl;
67
    }
68
69
    /**
70
     * @return RequestInterface
71
     */
72
    abstract protected function buildRequest();
73
74
    /**
75
     * @return Response
76
     */
77
    public function send()
78
    {
79
        $request = $this->buildRequest();
80
81
        //Apply standard header defaults
82
        $request->addHeader('Accept-language', 'en-CA');
83
        $request->addHeader('Authorization', base64_encode(
84
            $this->userid.':'.$this->password
85
        ));
86
87
        //Apply custom headers (with possible overwrite)
88
        $this->applyHeaders($request);
89
90
        return $request->send();
91
    }
92
93
    /**
94
     * @param RequestInterface $request
95
     */
96
    private function applyHeaders(RequestInterface $request)
97
    {
98
        foreach ($this->headers as $field => $value) {
99
            $request->addHeader($field, $value);
100
        }
101
    }
102
}
103