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 (#5)
by Cees-Jan
10:02
created

functions.php ➔ get_properties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
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
    $indent = str_repeat("\t", $indentLevel);
17
    $propertyIndent = str_repeat("\t", $indentLevel + 1);
18
19
    if ($resourceIndent) {
20
        echo $indent;
21
    }
22
    echo get_class($resource), PHP_EOL;
23
24
    foreach (get_properties($resource) as $property) {
25
        echo $propertyIndent, $property->getName(), ': ';
26
27
        $propertyValue = get_property($resource, $property->getName())->getValue($resource);
28
29
        if ($propertyValue instanceof ResourceInterface) {
30
            resource_pretty_print($propertyValue, $indentLevel + 1);
31
            continue;
32
        }
33
34
        if (is_array($propertyValue)) {
35
            echo '[', PHP_EOL;
36
            foreach ($propertyValue as $arrayValue) {
37
                resource_pretty_print($arrayValue, $indentLevel + 2, true);
38
            }
39
            echo $propertyIndent, ']', PHP_EOL;
40
            continue;
41
        }
42
43
        echo $propertyValue, PHP_EOL;
44
    }
45
}
46
47
/**
48
 * @param ResourceInterface $resource
49
 * @return array
50
 */
51
function get_properties(ResourceInterface $resource): array
52
{
53
    $class = new ReflectionClass($resource);
54
    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
    $class = new ReflectionClass($resource);
65
    $prop = $class->getProperty($property);
66
    $prop->setAccessible(true);
67
    return $prop;
68
}
69