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 ( 014a5f...fc3588 )
by Cees-Jan
01:22
created

functions.php ➔ throwable_encode()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 21
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4.0058

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 3
nop 1
dl 0
loc 21
ccs 13
cts 14
cp 0.9286
crap 4.0058
rs 9.0534
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['previous'] = $throwable->getPrevious();
29 2
    $json['trace'] = [];
30 2
    foreach ($throwable->getTrace() as $item) {
31 2
        $item['args'] = [];
32 2
        $json['trace'][] = $item;
33
    }
34
35 2
    return $json;
36
}
37
38
function throwable_json_decode($json)
39
{
40 1
    return throwable_decode(json_decode($json, true));
41
}
42
43
function throwable_decode($json)
44
{
45
    $properties = [
46 6
        'message',
47
        'code',
48
        'file',
49
        'line',
50
        'previous',
51
        'trace',
52
        'class',
53
    ];
54
55 6
    foreach ($properties as $property) {
56 6
        if (!isset($json[$property]) && !array_key_exists($property, $json)) {
57 6
            throw new NotAnEncodedThrowableException($json);
58
        }
59
    }
60
61 6
    array_pop($properties);
62
63 6
    $throwable = (new Instantiator())->instantiate($json['class']);
64 6
    $class = new ReflectionClass($json['class']);
65 6
    foreach ($properties as $key) {
66 6
        if (!$class->hasProperty($key)) {
67 4
            continue;
68
        }
69
70 6
        $property = new ReflectionProperty($json['class'], $key);
71 6
        $property->setAccessible(true);
72 6
        $property->setValue($throwable, $json[$key]);
73
    }
74
75 6
    return $throwable;
76
}
77