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 ( d88fce...019e6b )
by Alexander
03:10
created

ServiceClient::sendRequest()   A

Complexity

Conditions 2
Paths 8

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 9.0856
cc 2
eloc 14
nc 8
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
            $credentials = $this->getCredentials();
54
55
            $headers[] = 'Authorization: key='.$credentials->getAuthToken();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$headers was never initialized. Although not strictly required by PHP, it is generally a good practice to add $headers = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
56
            $headers[] = 'Content-Type: application/json';
57
58
            $response = $connection->post($serviceURL['url'], $headers, $notification['body']);
59
            $connection->getClient()->flush();
60
61
        } catch (\Exception $e) {
62
            throw new ClientException($e->getMessage());
63
        }
64
65
        new Response($response, $notification['recipients']);
66
67
        return true;
68
    }
69
}
70