Test Failed
Push — master ( 7b15c4...7a5412 )
by Dominik
01:48
created

DateFieldNormalizer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 53
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A normalizeField() 0 21 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Normalizer;
6
7
final class DateFieldNormalizer implements FieldNormalizerInterface
8
{
9
    /**
10
     * @var FieldNormalizerInterface
11
     */
12
    private $fieldNormalizer;
13
14
    /**
15
     * @var string
16
     */
17
    private $format;
18
19
    /**
20
     * @param FieldNormalizerInterface $fieldNormalizer
21
     * @param string                   $format
22
     */
23 4
    public function __construct(FieldNormalizerInterface $fieldNormalizer, string $format = 'c')
24
    {
25 4
        $this->fieldNormalizer = $fieldNormalizer;
26 4
        $this->format = $format;
27 4
    }
28
29
    /**
30
     * @param string                     $path
31
     * @param object                     $object
32
     * @param mixed                      $value
0 ignored issues
show
Bug introduced by
There is no parameter named $value. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
33
     * @param NormalizerContextInterface $context
34
     * @param NormalizerInterface|null   $normalizer
35
     *
36
     * @return mixed
37
     */
38 4
    public function normalizeField(
39
        string $path,
40
        $object,
41
        NormalizerContextInterface $context,
42
        NormalizerInterface $normalizer = null
43
    ) {
44 4
        $value = $this->fieldNormalizer->normalizeField($path, $object, $context, $normalizer);
45
46 4
        if (is_string($value)) {
47
            try {
48 2
                $value = new \DateTime($value);
49 1
            } catch (\Exception $exception) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
50
            }
51
        }
52
53 4
        if (!$value instanceof \DateTimeInterface) {
54 2
            return $value;
55
        }
56
57 2
        return $value->format($this->format);
58
    }
59
}
60