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.

WebhookHandler::handle()   A
last analyzed

Complexity

Conditions 4
Paths 7

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 10
cts 10
cp 1
rs 9.6333
c 0
b 0
f 0
cc 4
nc 7
nop 0
crap 4
1
<?php
2
3
namespace Vindi;
4
5
use Vindi\Exceptions\WebhookHandleException;
6
7
/**
8
 * Class WebhookHandler
9
 *
10
 * @package Vindi
11
 */
12
class WebhookHandler
13
{
14
    /**
15
     * @var string
16
     */
17
    public $file = 'php://input';
18
19
    /**
20
     * @return mixed
21
     * @throws \Vindi\Exceptions\WebhookHandleException
22
     */
23 6
    public function handle()
24
    {
25
        try {
26 6
            if (! $body = $this->getRawBody()) {
27 2
                throw new \Exception('Empty post body!');
28
            }
29
30 4
            if (! $decoded = json_decode($body)) {
31 2
                throw new \Exception('Unable to decode JSON from post body!');
32
            }
33
34 2
            reset($decoded);
35 2
            $event = current($decoded); // get first attribute from array, e.g.: event.
36
37 2
            return $event;
38 4
        } catch (\Exception $e) {
39 4
            throw new WebhookHandleException($e->getMessage(), $e->getCode(), $e);
40
        }
41
    }
42
43
    /**
44
     * @return string
45
     */
46 8
    public function getRawBody()
47
    {
48 8
        return file_get_contents($this->file);
49
    }
50
}
51