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
Pull Request — master (#1)
by Cees-Jan
07:38 queued 02:14
created

functions.php ➔ throwable_decode()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 33
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 21
nc 7
nop 1
dl 0
loc 33
ccs 14
cts 14
cp 1
crap 5
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus;
4
5
use Doctrine\Instantiator\Instantiator;
6
use Exception;
7
use ReflectionClass;
8
use ReflectionProperty;
9
use Throwable;
10
11
function throwable_json_encode($throwable)
12
{
13 1
    return json_encode(throwable_encode($throwable));
14
}
15
16
function throwable_encode($throwable)
17
{
18 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...
19
        throw new NotAThrowableException($throwable);
20
    }
21
22 2
    $json = [];
23 2
    $json['class'] = get_class($throwable);
24 2
    $json['message'] = $throwable->getMessage();
25 2
    $json['code'] = $throwable->getCode();
26 2
    $json['file'] = $throwable->getFile();
27 2
    $json['line'] = $throwable->getLine();
28 2
    $json['trace'] = [];
29 2
    foreach ($throwable->getTrace() as $item) {
30 2
        $item['args'] = [];
31 2
        $json['trace'][] = $item;
32
    }
33
34 2
    return $json;
35
}
36
37
function throwable_json_decode($json)
38
{
39 1
    return throwable_decode(json_decode($json, true));
40
}
41
42
function throwable_decode($json)
43
{
44
    $properties = [
45 6
        'message',
46
        'code',
47
        'file',
48
        'line',
49
        'trace',
50
        'class',
51
    ];
52
53 6
    foreach ($properties as $property) {
54 6
        if (!isset($json[$property])) {
55 6
            throw new NotAnEncodedThrowableException($json);
56
        }
57
    }
58
59 6
    array_pop($properties);
60
61 6
    $throwable = (new Instantiator())->instantiate($json['class']);
62 6
    $class = new ReflectionClass($json['class']);
63 6
    foreach ($properties as $key) {
64 6
        if (!$class->hasProperty($key)) {
65 4
            continue;
66
        }
67
68 6
        $property = new ReflectionProperty($json['class'], $key);
69 6
        $property->setAccessible(true);
70 6
        $property->setValue($throwable, $json[$key]);
71
    }
72
73 6
    return $throwable;
74
}
75