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.
Completed
Push — master ( b05701...c280e4 )
by Cees-Jan
02:04
created

functions.php ➔ throwable_decode()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 32
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5.0113

Importance

Changes 0
Metric Value
cc 5
eloc 20
nc 7
nop 1
dl 0
loc 32
ccs 12
cts 13
cp 0.9231
crap 5.0113
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus;
4
5
use Exception;
6
use ReflectionClass;
7
use ReflectionProperty;
8
use Throwable;
9
10
function throwable_json_encode($throwable)
11
{
12 1
    return json_encode(throwable_encode($throwable));
13
}
14
15
function throwable_encode($throwable)
16
{
17 2
    if (!($throwable instanceof Exception) && !($throwable instanceof Throwable)) {
0 ignored issues
show
Bug introduced by
The class Throwable does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
18
        throw new NotAThrowableException($throwable);
19
    }
20
21 2
    $json = [];
22 2
    $json['class'] = get_class($throwable);
23 2
    $json['message'] = $throwable->getMessage();
24 2
    $json['code'] = $throwable->getCode();
25 2
    $json['file'] = $throwable->getFile();
26 2
    $json['line'] = $throwable->getLine();
27 2
    $json['trace'] = [];
28 2
    foreach ($throwable->getTrace() as $item) {
29 2
        $item['args'] = [];
30 2
        $json['trace'][] = $item;
31
    }
32
33 2
    return $json;
34
}
35
36
function throwable_json_decode($json)
37
{
38 1
    return throwable_decode(json_decode($json, true));
39
}
40
41
function throwable_decode($json)
42
{
43
    $properties = [
44 2
        'message',
45
        'code',
46
        'file',
47
        'line',
48
        'trace',
49
        'class',
50
    ];
51
52 2
    foreach ($properties as $property) {
53 2
        if (!isset($json[$property])) {
54 2
            throw new NotAnEncodedThrowableException($json);
55
        }
56
    }
57
58 2
    array_pop($properties);
59
60 2
    $throwable = new $json['class']();
61 2
    foreach ($properties as $key) {
62 2
        if (!(new ReflectionClass($json['class']))->hasProperty($key)) {
63
            continue;
64
        }
65
66 2
        $property = new ReflectionProperty($json['class'], $key);
67 2
        $property->setAccessible(true);
68 2
        $property->setValue($throwable, $json[$key]);
69
    }
70
71 2
    return $throwable;
72
}
73