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 ( fd1b65...2c3c0a )
by Alexander
02:20
created

ServiceClient   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 7

Importance

Changes 6
Bugs 1 Features 0
Metric Value
wmc 4
c 6
b 1
f 0
lcom 2
cbo 7
dl 0
loc 64
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A createClient() 0 9 1
A sendRequest() 0 23 2
A getHeaders() 0 11 1
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\ResponseInterface;
13
use Zbox\UnifiedPush\NotificationService\ServiceClientBase;
14
use Zbox\UnifiedPush\Exception\ClientException;
15
use Buzz\Browser;
16
use Buzz\Client\MultiCurl;
17
18
/**
19
 * Class ServiceClient
20
 * @package Zbox\UnifiedPush\NotificationService\GCM
21
 */
22
class ServiceClient extends ServiceClientBase
23
{
24
    /**
25
     * Initializing HTTP client
26
     *
27
     * @return $this
28
     */
29
    protected function createClient()
30
    {
31
        $client = new MultiCurl();
32
        $client->setVerifyPeer(false);
33
34
        $this->serviceClient = new Browser($client);
35
36
        return $this;
37
    }
38
39
    /**
40
     * When the message is processed successfully, the HTTP response has a 200 status.
41
     * Body contains more information about the status of the message. When the request is rejected,
42
     * the HTTP response contains a non-200 status code.
43
     *
44
     * @throws ClientException
45
     * @return ResponseInterface
46
     */
47
    public function sendRequest()
48
    {
49
        $notification = $this->getNotificationOrThrowException();
50
51
        try {
52
            $connection  = $this->getClientConnection();
53
            $serviceURL  = $this->getServiceURL();
54
55
            $response =
56
                $connection->post(
57
                    $serviceURL['url'],
58
                    $this->getHeaders(),
59
                    $notification->getPayload()
60
                );
61
62
            $connection->getClient()->flush();
63
64
        } catch (\Exception $e) {
65
            throw new ClientException($e->getMessage());
66
        }
67
68
        return new Response($response, $notification->getRecipients());
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    protected function getHeaders()
75
    {
76
        /** @var \Zbox\UnifiedPush\NotificationService\GCM\Credentials $credentials */
77
        $credentials = $this->getCredentials();
78
79
        return
80
            array(
81
                sprintf('Authorization: key=%s', $credentials->getAuthToken()),
82
                'Content-Type: application/json'
83
            );
84
    }
85
}
86