Completed
Push — master ( 390b51...0e9cfd )
by Mario
11:43
created

AbstractDenormalizer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 41
c 0
b 0
f 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getValue() 0 4 2
A getValues() 0 4 1
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
    public const JSON_FORMAT = 'json';
12
13
    /**
14
     * @var \Symfony\Component\Serializer\Normalizer\DenormalizerInterface
15
     */
16
    protected $denormalizer;
17
18
    public function __construct(InternalDenormalizer $denormalizer)
19
    {
20
        $this->denormalizer = $denormalizer;
21
    }
22
23
    /**
24
     * @param string $key
25
     * @param array $data
26
     * @param string $class
27
     *
28
     * @return object|null
29
     */
30
    protected function getValue(string $key, array $data, string $class): ?object
31
    {
32
        return empty($data[$key]) ? null : $this->denormalizer->denormalize($data[$key], $class);
33
    }
34
35
    protected function getValues(array $key, array $data, string $class): ?object
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $data is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $class is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
38
    }
39
40
    protected function getDateTimeFromTimestamp($key, $data)
41
    {
42
        return empty($data[$key]) ? null : new \DateTimeImmutable("@{$data[$key]}");
43
    }
44
45
    protected function getData(string $key, array $values)
46
    {
47
        return empty($values[$key]) ? null :  $values[$key];
48
    }
49
}
50