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

createSubscribingConfiguration()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

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