Passed
Push — master ( 96a906...adf096 )
by Dominik
02:00
created

EmbedOneFieldNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 42
loc 42
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A normalizeField() 16 16 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Normalizer\Relation;
6
7
use Chubbyphp\Serialization\Accessor\AccessorInterface;
8
use Chubbyphp\Serialization\Normalizer\NormalizerContextInterface;
9
use Chubbyphp\Serialization\Normalizer\NormalizerInterface;
10
use Chubbyphp\Serialization\Normalizer\FieldNormalizerInterface;
11
use Chubbyphp\Serialization\SerializerLogicException;
12
13 View Code Duplication
final class EmbedOneFieldNormalizer implements FieldNormalizerInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
{
15
    /**
16
     * @var AccessorInterface
17
     */
18
    private $accessor;
19
20
    /**
21
     * @param AccessorInterface $accessor
22
     */
23
    public function __construct(AccessorInterface $accessor)
24
    {
25
        $this->accessor = $accessor;
26
    }
27
28
    /**
29
     * @param string                     $path
30
     * @param object                     $object
31
     * @param NormalizerContextInterface $context
32
     * @param NormalizerInterface|null   $normalizer
33
     *
34
     * @return mixed
35
     *
36
     * @throws SerializerLogicException
37
     */
38
    public function normalizeField(
39
        string $path,
40
        $object,
41
        NormalizerContextInterface $context,
42
        NormalizerInterface $normalizer = null
43
    ) {
44
        if (null === $normalizer) {
45
            throw SerializerLogicException::createMissingNormalizer($path);
46
        }
47
48
        if (null === $childObject = $this->accessor->getValue($object)) {
49
            return null;
50
        }
51
52
        return $normalizer->normalize($childObject, $context, $path);
53
    }
54
}
55