Passed
Push — master ( 3969cc...b281ee )
by Asmir
03:28 queued 01:08
created

EnumSubscriber::onPreSerializeEnum()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 6
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 11
rs 9.6111
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\EventDispatcher\Subscriber;
6
7
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
8
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
9
10
final class EnumSubscriber implements EventSubscriberInterface
11
{
12
    public function onPreSerializeEnum(PreSerializeEvent $event): void
13
    {
14
        $type = $event->getType();
15
16
        if (isset($type['name']) && ('enum' === $type['name'] || !is_a($type['name'], \UnitEnum::class, true))) {
0 ignored issues
show
Bug introduced by
The type UnitEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
            return;
18
        }
19
20
        $object = $event->getObject();
21
        $params = [get_class($object), $object instanceof \BackedEnum ? 'value' : 'name'];
0 ignored issues
show
Bug introduced by
The type BackedEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
        $event->setType('enum', $params);
23
    }
24
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public static function getSubscribedEvents()
29
    {
30
        return [
31
            ['event' => 'serializer.pre_serialize', 'method' => 'onPreSerializeEnum', 'interface' => \UnitEnum::class],
32
        ];
33
    }
34
}
35