SerializerListener::getSubscribingMethods()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
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