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.
Passed
Pull Request — master (#1061)
by Maxim
04:23 queued 01:35
created

Reporter::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 17
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 21
ccs 0
cts 21
cp 0
crap 6
rs 9.3142
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Util;
9
10
class Reporter
11
{
12
    const ENDPOINT = 'https://deployer.org/api/stats';
13
14
    /**
15
     * @param array $stats
16
     */
17
    public static function report(array $stats)
18
    {
19
        $pid = null;
20
        if (extension_loaded('pcntl')) {
21
            declare(ticks = 1);
22
            $pid = pcntl_fork();
23
        }
24
25
        if (is_null($pid) || $pid === -1) {
26
            // Fork fails or there is no `pcntl` extension.
27
            self::send($stats);
28
        } elseif ($pid === 0) {
29
            // Child process.
30
            posix_setsid();
31
            self::send($stats);
32
            // Close child process after doing job.
33
            exit(0);
34
        }
35
    }
36
37
    /**
38
     * @param array $stats
39
     */
40
    private static function send(array $stats)
41
    {
42
        if (extension_loaded('curl')) {
43
            $body = json_encode($stats, JSON_PRETTY_PRINT);
44
            $ch = curl_init(self::ENDPOINT);
45
            curl_setopt($ch, CURLOPT_HTTPHEADER, [
46
                'Content-Type: application/json',
47
                'Content-Length: ' . strlen($body)
48
            ]);
49
            curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
50
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
51
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
52
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
53
            curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
54
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
55
            curl_setopt($ch, CURLOPT_TIMEOUT, 5);
56
            curl_exec($ch);
57
        } else {
58
            file_get_contents(self::ENDPOINT . '?' . http_build_query($stats));
59
        }
60
    }
61
}
62