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 ( 925acd...ac3a4b )
by Cees-Jan
07:23 queued 05:22
created

Hydrator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace WyriHaximus\ApiClient\Transport;
5
6
use GeneratedHydrator\Configuration;
7
use WyriHaximus\ApiClient\Resource\ResourceInterface;
8
use Zend\Hydrator\HydratorInterface;
9
10
class Hydrator
11
{
12
    protected $options;
13
    protected $transport;
14
    protected $hydrators = [];
15
16 8
    public function __construct(Client $transport, array $options)
17
    {
18 8
        $this->transport = $transport;
19 8
        $this->options = $options;
20 8
    }
21
22 3
    public function hydrateFQCN($class, $json): ResourceInterface
23
    {
24 3
        $hydrator = $this->getHydrator($class);
25 3
        $object = $this->createObject($class);
26 3
        return $hydrator->hydrate($json, $object);
27
    }
28
29 2
    public function hydrate($class, $json): ResourceInterface
30
    {
31 2
        $fullClassName = $this->options['namespace'] . '\\' . $this->options['resource_namespace'] . '\\' . $class;
32 2
        return $this->hydrateFQCN($fullClassName, $json);
33
    }
34
35
    /**
36
     * Takes a fully qualified class name and extracts the data for that class from the given $object
37
     * @param $class
38
     * @param $object
39
     * @return array
40
     */
41 2
    public function extractFQCN($class, $object): array
42
    {
43 2
        return $this->getHydrator($class)->extract($object);
44
    }
45
46 1
    public function extract($class, $object): array
47
    {
48 1
        $fullClassName = $this->options['namespace'] . '\\' . $this->options['resource_namespace'] . '\\' . $class;
49 1
        return $this->extractFQCN($fullClassName, $object);
50
    }
51
52 1
    public function buildAsyncFromSync($resource, $object): ResourceInterface
53
    {
54 1
        return $this->hydrateFQCN(
55 1
            $this->options['namespace'] . '\\Async\\' . $resource,
56 1
            $this->extractFQCN(
57 1
                $this->options['namespace'] . '\\Sync\\' . $resource,
58
                $object
59
            )
60
        );
61
    }
62
63 3
    protected function getHydrator($class): HydratorInterface
64
    {
65 3
        if (isset($this->hydrators[$class])) {
66 1
            return $this->hydrators[$class];
67
        }
68
69 3
        $config = new Configuration($class);
70 3
        if (isset($this->options['resource_hydrator_cache_dir'])) {
71 3
            $config->setGeneratedClassesTargetDir($this->options['resource_hydrator_cache_dir']);
72
        }
73 3
        if (isset($this->options['resource_hydrator_namespace'])) {
74 3
            $config->setGeneratedClassesNamespace($this->options['resource_hydrator_namespace']);
75
        }
76 3
        $hydrator = $config->createFactory()->getHydratorClass();
77 3
        $this->hydrators[$class] = new $hydrator;
78
79 3
        return $this->hydrators[$class];
80
    }
81
82 3
    protected function createObject($class): ResourceInterface
83
    {
84 3
        $object = new $class();
85 3
        $object->setTransport($this->transport);
86 3
        return $object;
87
    }
88
}
89