Passed
Push — master ( 386b91...818dbd )
by Anton
06:54
created

Reporter::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
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\Utility;
9
10
/**
11
 * @codeCoverageIgnore
12
 */
13
class Reporter
14
{
15
    const ENDPOINT = 'https://deployer.org/api/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
            try {
28
                self::send($stats);
29
            } catch (\Throwable $e) {
30
                // pass
31
            }
32
        } elseif ($pid === 0) {
33
            // Child process.
34
            posix_setsid();
35
            try {
36
                self::send($stats);
37
            } catch (\Throwable $e) {
38
                // pass
39
            }
40
            // Close child process after doing job.
41
            exit(0);
0 ignored issues
show
Coding Style Compatibility introduced by Maksim Kuznetsov
The method report() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
42
        }
43
    }
44
45
    private static function send(array $stats)
46
    {
47
        Httpie::post(self::ENDPOINT)
48
            ->body($stats)
49
            ->setopt(CURLOPT_SSL_VERIFYPEER, false)
50
            ->send();
51
    }
52
}
53