Completed
Pull Request — master (#21)
by Valentyn
01:42
created

TranslatedEntitySerializer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 24
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A serialize() 0 7 1
1
<?php
2
3
namespace App\Translation;
4
5
use JMS\Serializer\Serializer;
6
use JMS\Serializer\SerializerInterface;
7
8
class TranslatedEntitySerializer
9
{
10
    /**
11
     * @var Serializer
12
     */
13
    protected $serializer;
14
15 9
    public function __construct(SerializerInterface $serializer)
16
    {
17 9
        if ($serializer instanceof Serializer === false) {
18
            throw new \InvalidArgumentException(sprintf('Serializer should be instance of %s instead %s given', Serializer::class, get_class($serializer)));
19
        }
20
21 9
        $this->serializer = $serializer;
22 9
    }
23
24 5
    public function serialize(TranslatableInterface $entity, string $locale): array
25
    {
26 5
        $translation = $this->serializer->toArray($entity->getTranslation($locale));
27 5
        $entity = $this->serializer->toArray($entity);
28
29 5
        return array_merge($translation, $entity);
30
    }
31
}