SerializerListener   A
last analyzed

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
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 41
ccs 13
cts 13
cp 1
rs 10

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 9
    public function __construct(Extractor $extractor)
21
    {
22 9
        $this->extractor = $extractor;
23 9
    }
24
25
    /** {@inheritDoc} */
26 1
    public static function getSubscribingMethods(): array
27
    {
28
        $entities = [
29 1
            Event::class,
30
        ];
31
32 1
        return self::createSubscribingConfiguration($entities);
33
    }
34
35
    /**
36
     * @param object $entity Entity object
37
     * @throws UnsupportedEntityException
38
     */
39 9
    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 9
        return $this->extractor->extract($entity);
42
    }
43
44 1
    private static function createSubscribingConfiguration(array $entities): array
45
    {
46 1
        $config = [];
47
48 1
        foreach ($entities as $entityClassName) {
49 1
            $config[] = ['format' => 'json', 'type' => $entityClassName, 'method' => 'extract'];
50
        }
51
52 1
        return $config;
53
    }
54
}
55