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::sendNotification()   B

Complexity

Conditions 3
Paths 15

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 2 Features 1
Metric Value
c 4
b 2
f 1
dl 0
loc 26
rs 8.8571
cc 3
eloc 16
nc 15
nop 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\MPNS;
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\MPNS
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
32
        $credentials      = $this->getCredentials();
33
        $isAuthenticated  = $credentials->isAuthenticated();
34
35
        $client->setVerifyPeer($isAuthenticated);
36
37
        if ($isAuthenticated) {
38
            $client->setOption(CURLOPT_SSLCERT, $credentials->getCertificatePassPhrase());
39
            $client->setOption(CURLOPT_SSLCERTPASSWD, $credentials->getCertificatePassPhrase());
40
        }
41
42
        $this->serviceClient = new Browser($client);
43
44
        return $this;
45
    }
46
47
    /**
48
     * @throws ClientException
49
     * @return bool
50
     */
51
    public function sendRequest()
52
    {
53
        $notification = $this->getNotificationOrThrowException();
54
55
        try {
56
            $connection  = $this->getClientConnection();
57
            $serviceURL  = $this->getServiceURL();
58
            $url         = str_replace('[TOKEN]', $notification['recipients'][0], $serviceURL['url']);
59
60
            $headers = array();
61
            $headers[] = 'Accept: application/*';
62
            $headers[] = 'Content-Type: text/xml';
63
64
            foreach ($notification['options'] as $key => $value) {
65
                $headers[] = $key . ': ' . $value;
66
            }
67
68
            $response = $connection->post($url, $headers, $notification['body']);
69
            $connection->getClient()->flush();
70
71
        } catch (\Exception $e) {
72
            throw new ClientException($e->getMessage());
73
        }
74
75
        new Response($response, $notification['recipients']);
76
77
        return true;
78
    }
79
}
80