Test Setup Failed
Push — master ( 5581c1...eb296b )
by Petr
03:03
created

SerializerListener   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
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 41
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribingMethods() 0 8 1
A extract() 0 4 1
A createSubscribingConfiguration() 0 10 2
1
<?php
2
3
namespace AppBundle\EventListener;
4
5
use AppBundle\Entity\Event;
6
use AppBundle\Exception\UnsupportedEntityException;
7
use AppBundle\Service\Extractor\Extractor;
8
use JMS\Serializer\Handler\SubscribingHandlerInterface;
9
use JMS\Serializer\JsonSerializationVisitor;
10
11
/**
12
 * @author Vehsamrak
13
 */
14
class SerializerListener implements SubscribingHandlerInterface
15
{
16
17
    /** @var Extractor */
18
    private $extractor;
19
20
    public function __construct(Extractor $extractor)
21 6
    {
22
        $this->extractor = $extractor;
23 6
    }
24 6
25
    /** {@inheritDoc} */
26
    public static function getSubscribingMethods(): array
27 1
    {
28
        $entities = [
29
            Event::class,
30
        ];
31
32
        return self::createSubscribingConfiguration($entities);
33
    }
34 1
35
    /**
36
     * @param object $entity Entity object
37
     * @throws UnsupportedEntityException
38
     */
39
    public function extract(JsonSerializationVisitor $visitor, $entity): array
0 ignored issues
show
Unused Code introduced by
The parameter $visitor 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...
40
    {
41
        return $this->extractor->extract($entity);
42 6
    }
43
44 6
    private static function createSubscribingConfiguration(array $entities): array
45
    {
46
        $config = [];
47
48
        foreach ($entities as $entityClassName) {
49
            return ['format' => 'json', 'type' => $entityClassName, 'method' => 'extract'];
50
        }
51
52
        return $config;
53
    }
54
}
55