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 ( 9cf4f5...f85fc1 )
by Cees-Jan
12:06 queued 08:18
created

Hydrator   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 79
ccs 0
cts 36
cp 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A hydrateFQCN() 0 6 1
A hydrate() 0 5 1
A extractFQCN() 0 4 1
A extract() 0 5 1
A buildAsyncFromSync() 0 10 1
A getHydrator() 0 18 4
A createObject() 0 6 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
    public function __construct(Client $transport, array $options)
17
    {
18
        $this->transport = $transport;
19
        $this->options = $options;
20
    }
21
22
    public function hydrateFQCN($class, $json): ResourceInterface
23
    {
24
        $hydrator = $this->getHydrator($class);
25
        $object = $this->createObject($class);
26
        return $hydrator->hydrate($json, $object);
27
    }
28
29
    public function hydrate($class, $json): ResourceInterface
30
    {
31
        $fullClassName = $this->options['namespace'] . '\\' . $this->options['resource_namespace'] . '\\' . $class;
32
        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
    public function extractFQCN($class, $object): array
42
    {
43
        return $this->getHydrator($class)->extract($object);
44
    }
45
46
    public function extract($class, $object): array
47
    {
48
        $fullClassName = $this->options['namespace'] . '\\' . $this->options['resource_namespace'] . '\\' . $class;
49
        return $this->extractFQCN($fullClassName, $object);
50
    }
51
52
    public function buildAsyncFromSync($resource, $object): ResourceInterface
53
    {
54
        return $this->hydrateFQCN(
55
            $this->options['namespace'] . '\\Async\\' . $resource,
56
            $this->extractFQCN(
57
                $this->options['namespace'] . '\\Sync\\' . $resource,
58
                $object
59
            )
60
        );
61
    }
62
63
    protected function getHydrator($class): HydratorInterface
64
    {
65
        if (isset($this->hydrators[$class])) {
66
            return $this->hydrators[$class];
67
        }
68
69
        $config = new Configuration($class);
70
        if (isset($this->options['resource_hydrator_cache_dir'])) {
71
            $config->setGeneratedClassesTargetDir($this->options['resource_hydrator_cache_dir']);
72
        }
73
        if (isset($this->options['resource_hydrator_namespace'])) {
74
            $config->setGeneratedClassesNamespace($this->options['resource_hydrator_namespace']);
75
        }
76
        $hydrator = $config->createFactory()->getHydratorClass();
77
        $this->hydrators[$class] = new $hydrator;
78
79
        return $this->hydrators[$class];
80
    }
81
82
    protected function createObject($class): ResourceInterface
83
    {
84
        $object = new $class();
85
        $object->setTransport($this->transport);
86
        return $object;
87
    }
88
}
89