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
Pull Request — master (#46)
by Andy
02:53
created

HttpGuzzlClient::getDefaultRequestOptions()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 13
cts 13
cp 1
rs 9.4285
cc 3
eloc 10
nc 2
nop 0
crap 3
1
<?php
2
/**
3
 * @package: chapi
4
 *
5
 * @author:  msiebeneicher
6
 * @since:   2015-07-28
7
 *
8
 */
9
10
namespace Chapi\Component\Http;
11
12
use Chapi\Exception\HttpConnectionException;
13
use Chapi\Entity\Http\AuthEntity;
14
use GuzzleHttp\ClientInterface;
15
16
class HttpGuzzlClient implements HttpClientInterface
17
{
18
    const DEFAULT_CONNECTION_TIMEOUT = 5;
19
    const DEFAULT_TIMEOUT = 30;
20
21
    /**
22
     * @var ClientInterface
23
     */
24
    private $oGuzzelClient;
25
26
    /**
27
     * @var AuthEntity
28
     */
29
    private $oAuthEntity;
30
31
    /**
32
     * @param ClientInterface $oGuzzelClient
33
     * @param AuthEntity $oAuthEntity
34
     */
35 7
    public function __construct(
36
        ClientInterface $oGuzzelClient,
37
        AuthEntity $oAuthEntity
38
    )
39
    {
40 7
        $this->oGuzzelClient = $oGuzzelClient;
41 7
        $this->oAuthEntity = $oAuthEntity;
42 7
    }
43
44
    /**
45
     * @param string $sUrl
46
     * @return HttpClientResponseInterface
47
     * @throws HttpConnectionException
48
     */
49 3
    public function get($sUrl)
50
    {
51 3
        $_aRequestOptions = $this->getDefaultRequestOptions();
52
53
        try
54
        {
55 3
            $_oResponse = $this->oGuzzelClient->get($sUrl, $_aRequestOptions);
56 2
            return new HttpGuzzlResponse($_oResponse);
57
        }
58 1
        catch (\Exception $oException)
59
        {
60 1
            throw new HttpConnectionException(
61 1
                sprintf('Can\'t get response from "%s"', $this->oGuzzelClient->getBaseUrl() . $sUrl),
62 1
                0,
63
                $oException
64 1
            );
65
        }
66
    }
67
68
    /**
69
     * @param string $sUrl
70
     * @param mixed $mPostData
71
     * @return HttpGuzzlResponse
72
     */
73 2
    public function postJsonData($sUrl, $mPostData)
74
    {
75 2
        $_aRequestOptions = $this->getDefaultRequestOptions();
76 2
        $_aRequestOptions['json'] = $mPostData;
77
78 2
        $_oRequest = $this->oGuzzelClient->createRequest('post', $sUrl, $_aRequestOptions);
79 2
        $_oResponse = $this->oGuzzelClient->send($_oRequest);
80
81 2
        return new HttpGuzzlResponse($_oResponse);
82
    }
83
84
    /**
85
     * @param string $sUrl
86
     * @return HttpGuzzlResponse
87
     */
88 2
    public function delete($sUrl)
89
    {
90 2
        $_aRequestOptions = $this->getDefaultRequestOptions();
91 2
        $_oResponse = $this->oGuzzelClient->delete($sUrl, $_aRequestOptions);
92 2
        return new HttpGuzzlResponse($_oResponse);
93
    }
94
95
    /**
96
     * Returns default options for the HTTP request.
97
     * If an username and password is provided, auth
98
     * header will be applied as well.
99
     *
100
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<string,integer|string[]>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
101
     */
102 7
    private function getDefaultRequestOptions() {
103
        $_aRequestOptions = [
104 7
            'connect_timeout' => self::DEFAULT_CONNECTION_TIMEOUT,
105
            'timeout' => self::DEFAULT_TIMEOUT
106 7
        ];
107
108 7
        if (!empty($this->oAuthEntity->username)
109 7
            && !empty($this->oAuthEntity->password)
110 3
        )
111 7
        {
112 3
            $_aRequestOptions['auth'] = [
113 3
                $this->oAuthEntity->username,
114 3
                $this->oAuthEntity->password
115 3
            ];
116 3
        }
117
118 7
        return $_aRequestOptions;
119
    }
120
}