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.

functions.php ➔ resource_pretty_print()   B
last analyzed

Complexity

Conditions 6
Paths 10

Size

Total Lines 32
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 19
nc 10
nop 3
dl 0
loc 32
ccs 19
cts 19
cp 1
crap 6
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace WyriHaximus\ApiClient;
4
5
use ReflectionClass;
6
use ReflectionProperty;
7
use WyriHaximus\ApiClient\Resource\ResourceInterface;
8
9
/**
10
 * @param ResourceInterface $resource
11
 * @param int $indentLevel
12
 * @param bool $resourceIndent
13
 */
14
function resource_pretty_print(ResourceInterface $resource, int $indentLevel = 0, bool $resourceIndent = false)
15
{
16 1
    $indent = str_repeat("\t", $indentLevel);
17 1
    $propertyIndent = str_repeat("\t", $indentLevel + 1);
18
19 1
    if ($resourceIndent) {
20 1
        echo $indent;
21
    }
22 1
    echo get_class($resource), PHP_EOL;
23
24 1
    foreach (get_properties($resource) as $property) {
25 1
        echo $propertyIndent, $property->getName(), ': ';
26
27 1
        $propertyValue = get_property($resource, $property->getName())->getValue($resource);
28
29 1
        if ($propertyValue instanceof ResourceInterface) {
30 1
            resource_pretty_print($propertyValue, $indentLevel + 1);
31 1
            continue;
32
        }
33
34 1
        if (is_array($propertyValue)) {
35 1
            echo '[', PHP_EOL;
36 1
            foreach ($propertyValue as $arrayValue) {
37 1
                resource_pretty_print($arrayValue, $indentLevel + 2, true);
38
            }
39 1
            echo $propertyIndent, ']', PHP_EOL;
40 1
            continue;
41
        }
42
43 1
        echo $propertyValue, PHP_EOL;
44
    }
45 1
}
46
47
/**
48
 * @param ResourceInterface $resource
49
 * @return array
50
 */
51
function get_properties(ResourceInterface $resource): array
52
{
53 2
    $class = new ReflectionClass($resource);
54 2
    return $class->getProperties();
55
}
56
57
/**
58
 * @param ResourceInterface $resource
59
 * @param string $property
60
 * @return ReflectionProperty
61
 */
62
function get_property(ResourceInterface $resource, string $property)
63
{
64 2
    $class = new ReflectionClass($resource);
65 2
    $prop = $class->getProperty($property);
66 2
    $prop->setAccessible(true);
67 2
    return $prop;
68
}
69