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 ( 3abaaf...dcd0c7 )
by Cees-Jan
8s
created

Hydrator   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

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

8 Methods

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