Completed
Push — master ( c48d97...353cc7 )
by Mario
13:39 queued 03:42
created

AbstractDenormalizer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 39
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 4 2
A getDateTimeFromTimestamp() 0 4 2
A getData() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\OpenWeatherMap\Denormalizer;
6
7
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface as InternalDenormalizer;
8
9
abstract class AbstractDenormalizer implements DenormalizerInterface
10
{
11
    /**
12
     * @var \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
13
     */
14
    protected $denormalizer;
15
16
    /**
17
     * AbstractDenormalizer constructor.
18
     *
19
     * @param \Symfony\Component\Serializer\Normalizer\DenormalizerInterface $denormalizer
20
     */
21
    public function __construct(InternalDenormalizer $denormalizer)
22
    {
23
        $this->denormalizer = $denormalizer;
24
    }
25
26
    /**
27
     * @param string $key
28
     * @param array $data
29
     * @param string $class
30
     *
31
     * @return object|null
32
     */
33
    protected function getValue(string $key, array $data, string $class): ?object
34
    {
35
        return empty($data[$key]) ? null : $this->denormalizer->denormalize($data[$key], $class);
36
    }
37
38
    protected function getDateTimeFromTimestamp($key, $data)
39
    {
40
        return empty($data[$key]) ? null : new \DateTimeImmutable("@{$data[$key]}");
41
    }
42
43
    protected function getData(string $key, array $values)
44
    {
45
        return $values[$key] === null ? null :  $values[$key];
46
    }
47
}
48