Issues (210)

src/Handler/StdClassHandler.php (4 issues)

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\Type\Type;
11
use JMS\Serializer\Visitor\SerializationVisitorInterface;
12
13
/**
14
 * @author Asmir Mustafic <[email protected]>
15
 *
16
 * @phpstan-import-type TypeArray from Type
17 329
 */
18
final class StdClassHandler implements SubscribingHandlerInterface
19 329
{
20 329
    /**
21
     * {@inheritdoc}
22 329
     */
23 329
    public static function getSubscribingMethods()
24 329
    {
25 329
        $methods = [];
26 329
        $formats = ['json', 'xml'];
27 329
28
        foreach ($formats as $format) {
29
            $methods[] = [
30
                'direction' => GraphNavigatorInterface::DIRECTION_SERIALIZATION,
31 329
                'type' => \stdClass::class,
32
                'format' => $format,
33
                'method' => 'serializeStdClass',
34 7
            ];
35
        }
36 7
37 7
        return $methods;
38
    }
39 7
40 4
    /**
41 4
     * @param TypeArray $type
0 ignored issues
show
The type JMS\Serializer\Handler\TypeArray 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...
42
     *
43
     * @return mixed
44 7
     */
45
    public function serializeStdClass(SerializationVisitorInterface $visitor, \stdClass $stdClass, array $type, SerializationContext $context)
0 ignored issues
show
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

45
    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...
46
    {
47
        $classMetadata = $context->getMetadataFactory()->getMetadataForClass('stdClass');
48
        $visitor->startVisitingObject($classMetadata, $stdClass, ['name' => 'stdClass']);
0 ignored issues
show
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

48
        $visitor->startVisitingObject(/** @scrutinizer ignore-type */ $classMetadata, $stdClass, ['name' => 'stdClass']);
Loading history...
49
50
        foreach ((array) $stdClass as $name => $value) {
51
            $metadata = new StaticPropertyMetadata('stdClass', $name, $value);
52
            $visitor->visitProperty($metadata, $value);
53
        }
54
55
        return $visitor->endVisitingObject($classMetadata, $stdClass, ['name' => 'stdClass']);
0 ignored issues
show
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

55
        return $visitor->endVisitingObject(/** @scrutinizer ignore-type */ $classMetadata, $stdClass, ['name' => 'stdClass']);
Loading history...
56
    }
57
}
58