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 ➔ get_property()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace ApiClients\Foundation;
4
5
use ApiClients\Foundation\Resource\ResourceInterface;
6
use ReflectionClass;
7
use ReflectionProperty;
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): void
15
{
16 1
    $indent = \str_repeat("\t", $indentLevel);
17 1
    $propertyIndent = \str_repeat("\t", $indentLevel + 1);
18 1
    $arrayIndent = \str_repeat("\t", $indentLevel + 2);
19
20 1
    if ($resourceIndent) {
21 1
        echo $indent;
22
    }
23 1
    echo \get_class($resource), \PHP_EOL;
24
25 1
    foreach (get_properties($resource) as $property) {
26 1
        echo $propertyIndent, $property->getName(), ': ';
27
28 1
        $propertyValue = get_property($resource, $property->getName())->getValue($resource);
29
30 1
        if ($propertyValue instanceof ResourceInterface) {
31 1
            resource_pretty_print($propertyValue, $indentLevel + 1);
32 1
            continue;
33
        }
34
35 1
        if (\is_array($propertyValue)) {
36 1
            echo '[', \PHP_EOL;
37 1
            foreach ($propertyValue as $arrayKey => $arrayValue) {
38 1
                if ($arrayValue instanceof ResourceInterface) {
39 1
                    resource_pretty_print($arrayValue, $indentLevel + 2, true);
40 1
                    continue;
41
                }
42
43
                echo $arrayIndent, $arrayKey, ': ';
44
45
                if (\is_array($arrayValue)) {
46
                    array_pretty_print($arrayValue, $arrayIndent + 2);
47
                    continue;
48
                }
49
50
                echo $arrayValue, \PHP_EOL;
51
            }
52 1
            echo $propertyIndent, ']', \PHP_EOL;
53 1
            continue;
54
        }
55
56 1
        echo $propertyValue, \PHP_EOL;
57
    }
58 1
}
59
60
/**
61
 * @param array $array
62
 * @param int   $indentLevel
63
 */
64
function array_pretty_print(array $array, int $indentLevel = 0): void
65
{
66 1
    $indent = \str_repeat("\t", $indentLevel);
67 1
    $propertyIndent = \str_repeat("\t", $indentLevel + 1);
68 1
    echo '[', \PHP_EOL;
69 1
    foreach ($array as $key => $value) {
70 1
        echo $propertyIndent, $key, ': ';
71 1
        if (\is_array($value)) {
72 1
            array_pretty_print($value, $indentLevel + 1);
73 1
            continue;
74
        }
75
76 1
        echo $value, \PHP_EOL;
77
    }
78 1
    echo $indent, ']', \PHP_EOL;
79 1
}
80
81
/**
82
 * @param  ResourceInterface $resource
83
 * @return array
84
 */
85
function get_properties(ResourceInterface $resource): array
86
{
87 2
    $class = new ReflectionClass($resource);
88
89 2
    return $class->getProperties();
90
}
91
92
/**
93
 * @param  ResourceInterface  $resource
94
 * @param  string             $property
95
 * @return ReflectionProperty
96
 */
97
function get_property(ResourceInterface $resource, string $property)
98
{
99 2
    $class = new ReflectionClass($resource);
100 2
    $prop = $class->getProperty($property);
101 2
    $prop->setAccessible(true);
102
103 2
    return $prop;
104
}
105