Passed
Push — master ( e008f3...ac9d28 )
by Petr
03:49
created

SerializerListener::extract()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
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\GraphNavigator;
9
use JMS\Serializer\Handler\SubscribingHandlerInterface;
10
use JMS\Serializer\JsonSerializationVisitor;
11
12
/**
13
 * @author Vehsamrak
14
 */
15
class SerializerListener implements SubscribingHandlerInterface
16
{
17
18
    /** @var Extractor */
19
    private $extractor;
20
21 6
    public function __construct(Extractor $extractor)
22
    {
23 6
        $this->extractor = $extractor;
24 6
    }
25
26
    /** {@inheritDoc} */
27 1
    public static function getSubscribingMethods(): array
28
    {
29
        return [
30
            [
31 1
                'direction' => GraphNavigator::DIRECTION_SERIALIZATION,
32 1
                'format'    => 'json',
33
                'type'      => Event::class,
34 1
                'method'    => 'extract',
35 1
            ],
36
        ];
37
    }
38
39
    /**
40
     * @param object $entity Entity object
41
     * @throws UnsupportedEntityException
42
     */
43 6
    public function extract(
44
        JsonSerializationVisitor $visitor,
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...
45
        $entity
46
    ): array
47
    {
48 6
        return $this->extractor->extract($entity);
49
    }
50
}
51