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 (#13)
by Cees-Jan
03:40 queued 01:42
created

CollectionHandler::hydrate()   C

Complexity

Conditions 7
Paths 5

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 0
cts 16
cp 0
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 16
nc 5
nop 3
crap 56
1
<?php
2
declare(strict_types=1);
3
4
namespace ApiClients\Foundation\Hydrator\Annotations\Handler;
5
6
use ApiClients\Foundation\Hydrator\AnnotationInterface;
7
use ApiClients\Foundation\Hydrator\Annotations\Collection;
8
use ApiClients\Foundation\Hydrator\HandlerInterface;
9
use ApiClients\Foundation\Resource\ResourceInterface;
10
11
class CollectionHandler extends AbstractHandler implements HandlerInterface
12
{
13
    public function hydrate(AnnotationInterface $annotation, array $json, ResourceInterface $object): array
14
    {
15
        if (!($annotation instanceof Collection)) {
16
            return $json;
17
        }
18
19
        foreach ($annotation->properties() as $property) {
20
            if (!isset($json[$property])) {
21
                $json[$property] = [];
22
                continue;
23
            }
24
25
            $array = $json[$property];
26
27
            if (!is_array($array)) {
28
                continue;
29
            }
30
31
            $json[$property] = [];
32
            foreach ($array as $resource) {
33
                if ($resource === null) {
34
                    continue;
35
                }
36
37
                $json[$property][] = $this->getHydrator()->hydrate($annotation->get($property), $resource);
38
            }
39
        }
40
41
        return $json;
42
    }
43
44
    public function extract(AnnotationInterface $annotation, ResourceInterface $object, array $json): array
45
    {
46
        if (!($annotation instanceof Collection)) {
47
            return $json;
48
        }
49
50
        foreach ($annotation->properties() as $property) {
51
            $array = $json[$property];
52
            $json[$property] = [];
53
            foreach ($array as $resource) {
54
                $json[$property][] = $this->getHydrator()->extract($annotation->get($property), $resource);
55
            }
56
        }
57
58
        return $json;
59
    }
60
}
61