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 — master ( 019e6b...cdb240 )
by Alexander
02:28
created

ServiceClient::sendRequest()   B

Complexity

Conditions 2
Paths 5

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 2
eloc 15
nc 5
nop 0
1
<?php
2
3
/*
4
 * (c) Alexander Zhukov <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Zbox\UnifiedPush\NotificationService\GCM;
11
12
use Zbox\UnifiedPush\NotificationService\ServiceClientBase;
13
use Zbox\UnifiedPush\Exception\ClientException;
14
use Buzz\Browser;
15
use Buzz\Client\MultiCurl;
16
17
/**
18
 * Class ServiceClient
19
 * @package Zbox\UnifiedPush\NotificationService\GCM
20
 */
21
class ServiceClient extends ServiceClientBase
22
{
23
    /**
24
     * Initializing HTTP client
25
     *
26
     * @return $this
27
     */
28
    protected function createClient()
29
    {
30
        $client = new MultiCurl();
31
        $client->setVerifyPeer(false);
32
33
        $this->serviceClient = new Browser($client);
34
35
        return $this;
36
    }
37
38
    /**
39
     * When the message is processed successfully, the HTTP response has a 200 status.
40
     * Body contains more information about the status of the message. When the request is rejected,
41
     * the HTTP response contains a non-200 status code.
42
     *
43
     * @throws ClientException
44
     * @return bool
45
     */
46
    public function sendRequest()
47
    {
48
        $notification = $this->getNotificationOrThrowException();
49
50
        try {
51
            $connection  = $this->getClientConnection();
52
            $serviceURL  = $this->getServiceURL();
53
54
            $response =
55
                $connection->post(
56
                    $serviceURL['url'],
57
                    $this->getHeaders(),
58
                    $notification->getPayload()
59
                );
60
61
            $connection->getClient()->flush();
62
63
        } catch (\Exception $e) {
64
            throw new ClientException($e->getMessage());
65
        }
66
67
        new Response($response, $notification->getRecipients());
68
69
        return true;
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    protected function getHeaders()
76
    {
77
        /** @var \Zbox\UnifiedPush\NotificationService\GCM\Credentials $credentials */
78
        $credentials = $this->getCredentials();
79
80
        return
81
            array(
82
                sprintf('Authorization: key=%s', $credentials->getAuthToken()),
83
                'Content-Type: application/json'
84
            );
85
    }
86
}
87