StdClassHandler   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 36
ccs 17
cts 17
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serializeStdClass() 0 11 2
A getSubscribingMethods() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace JMS\Serializer\Handler;
6
7
use JMS\Serializer\GraphNavigatorInterface;
8
use JMS\Serializer\Metadata\StaticPropertyMetadata;
9
use JMS\Serializer\SerializationContext;
10
use JMS\Serializer\Visitor\SerializationVisitorInterface;
11
12
/**
13
 * @author Asmir Mustafic <[email protected]>
14
 */
15
final class StdClassHandler implements SubscribingHandlerInterface
16
{
17 329
    /**
18
     * {@inheritdoc}
19 329
     */
20 329
    public static function getSubscribingMethods()
21
    {
22 329
        $methods = [];
23 329
        $formats = ['json', 'xml'];
24 329
25 329
        foreach ($formats as $format) {
26 329
            $methods[] = [
27 329
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
28
                'type' => \stdClass::class,
29
                'format' => $format,
30
                'method' => 'serializeStdClass',
31 329
            ];
32
        }
33
34 7
        return $methods;
35
    }
36 7
37 7
    /**
38
     * @return mixed
39 7
     */
40 4
    public function serializeStdClass(SerializationVisitorInterface $visitor, \stdClass $stdClass, array $type, SerializationContext $context)
0 ignored issues
show
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

40
    public function serializeStdClass(SerializationVisitorInterface $visitor, \stdClass $stdClass, /** @scrutinizer ignore-unused */ array $type, SerializationContext $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...
41 4
    {
42
        $classMetadata = $context->getMetadataFactory()->getMetadataForClass('stdClass');
43
        $visitor->startVisitingObject($classMetadata, $stdClass, ['name' => 'stdClass']);
0 ignored issues
show
Bug introduced by
It seems like $classMetadata can also be of type Metadata\ClassHierarchyMetadata and null; however, parameter $metadata of JMS\Serializer\Visitor\S...::startVisitingObject() does only seem to accept JMS\Serializer\Metadata\ClassMetadata, maybe add an additional type check? ( Ignorable by Annotation )

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

43
        $visitor->startVisitingObject(/** @scrutinizer ignore-type */ $classMetadata, $stdClass, ['name' => 'stdClass']);
Loading history...
44 7
45
        foreach ((array) $stdClass as $name => $value) {
46
            $metadata = new StaticPropertyMetadata('stdClass', $name, $value);
47
            $visitor->visitProperty($metadata, $value);
48
        }
49
50
        return $visitor->endVisitingObject($classMetadata, $stdClass, ['name' => 'stdClass']);
0 ignored issues
show
Bug introduced by
It seems like $classMetadata can also be of type Metadata\ClassHierarchyMetadata and null; however, parameter $metadata of JMS\Serializer\Visitor\S...ce::endVisitingObject() does only seem to accept JMS\Serializer\Metadata\ClassMetadata, maybe add an additional type check? ( Ignorable by Annotation )

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

50
        return $visitor->endVisitingObject(/** @scrutinizer ignore-type */ $classMetadata, $stdClass, ['name' => 'stdClass']);
Loading history...
51
    }
52
}
53