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   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 39
c 0
b 0
f 0
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 19 4
A getRawBody() 0 4 1
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