Passed
Push — master ( 5e6b27...171516 )
by Caen
03:14
created

getCoverage()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
c 2
b 0
f 0
nc 3
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
define('TIME_START', microtime(true));
4
5
/**
6
 * @internal This script is used to ping the CI server with the type coverage results.
7
 *
8
 * @example php __FILE__ ${{ secrets.CI_SERVER_TOKEN }} ${{ github.event.pull_request.head.sha }} ${{ github.head_ref }}
9
 *
10
 * @uses vendor/bin/psalm > psalmout.txt
11
 */
12
echo "Pinging CI server\n";
13
14
$token = $argv[1] ?? exit(400);
15
$commit = $argv[2] ?? exit(400);
16
$branch = $argv[3] ?? 'master';
17
18
19
$data = [
20
    'commit' => $commit,
21
    'report' => file_get_contents('type-coverage.json') ?? exit(404),
22
];
23
24
$url = 'https://ci.hydephp.se/api/github/actions/type-coverage';
25
26
$curl = curl_init($url);
27
curl_setopt($curl, CURLOPT_URL, $url);
28
curl_setopt($curl, CURLOPT_POST, true);
29
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
30
31
$headers = [
32
    'Accept: application/json',
33
    "Authorization: Bearer $token",
34
    'Content-Type: application/json',
35
];
36
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
37
38
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
39
40
$resp = curl_exec($curl);
41
curl_close($curl);
42
var_dump($resp);
43
44
if (curl_getinfo($curl, CURLINFO_HTTP_CODE) !== 200) {
45
    echo 'Type coverage report failed to send';
46
    exit(curl_getinfo($curl, CURLINFO_HTTP_CODE));
47
}
48