Passed
Pull Request — master (#1384)
by
unknown
02:55
created

BackedEnumHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 16
dl 0
loc 51
rs 10
c 1
b 0
f 1
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A deserializeBackedEnum() 0 3 1
A serializeBackedEnum() 0 3 1
A getSubscribingMethods() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Handler;
6
7
use JMS\Serializer\Context;
8
use JMS\Serializer\GraphNavigatorInterface;
9
use JMS\Serializer\JsonSerializationVisitor;
10
use JMS\Serializer\JsonDeserializationVisitor;
11
12
class BackedEnumHandler implements SubscribingHandlerInterface
13
{
14
    /**
15
     * {@inheritDoc}
16
     */
17
    public static function getSubscribingMethods(): array
18
    {
19
        $methods = [];
20
        foreach (['json', 'xml'] as $format) {
21
            $methods[] = [
22
                'type' => \BackedEnum::class,
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...
23
                'format' => $format,
24
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
25
                'method' => 'serializeBackedEnum',
26
            ];
27
28
            $methods[] = [
29
                'type' => \BackedEnum::class,
30
                'direction' => GraphNavigatorInterface::DIRECTION_DESERIALIZATION,
31
                'format' => $format,
32
                'method' => 'deserializeBackedEnum',
33
            ];
34
        }
35
36
        return $methods;
37
    }
38
39
    /**
40
     * @param JsonSerializationVisitor $visitor
41
     * @param BackedEnumHandler        $object
42
     * @param array                    $type
43
     * @param Context                  $context
44
     *
45
     * @return null|string|int
46
     */
47
    public function serializeBackedEnum(JsonSerializationVisitor $visitor, $object, array $type, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
    public function serializeBackedEnum(/** @scrutinizer ignore-unused */ JsonSerializationVisitor $visitor, $object, array $type, Context $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
    public function serializeBackedEnum(JsonSerializationVisitor $visitor, $object, array $type, /** @scrutinizer ignore-unused */ Context $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

47
    public function serializeBackedEnum(JsonSerializationVisitor $visitor, $object, /** @scrutinizer ignore-unused */ array $type, Context $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
48
    {
49
        return $object->value;
0 ignored issues
show
Bug Best Practice introduced by
The property value does not exist on JMS\Serializer\Handler\BackedEnumHandler. Did you maybe forget to declare it?
Loading history...
50
    }
51
52
    /**
53
     * @param JsonDeserializationVisitor $visitor
54
     * @param null|string|int            $value
55
     * @param array                      $type
56
     * @param Context                    $context
57
     *
58
     * @return null|\BackedEnum
59
     */
60
    public function deserializeBackedEnum(JsonDeserializationVisitor $visitor, $value, array $type, Context $context)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
    public function deserializeBackedEnum(/** @scrutinizer ignore-unused */ JsonDeserializationVisitor $visitor, $value, array $type, Context $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

60
    public function deserializeBackedEnum(JsonDeserializationVisitor $visitor, $value, array $type, /** @scrutinizer ignore-unused */ Context $context)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
61
    {
62
        return $type['enum']::tryFrom($value);
63
    }
64
}
65