• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jojo1981 / jms-serializer-handlers / 17515892676

06 Sep 2025 02:49PM UTC coverage: 75.229%. Remained the same
17515892676

push

github

jojo1981
Fix: Make compatible with PHP versions: ^8.0|^8.1|^8.2|^8.3|^8.4. Closes #1
https://github.com/jojo1981/jms-serializer-handlers/issues/1

164 of 218 relevant lines covered (75.23%)

27.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/src/TypedCollectionObjectConstructorDecorator.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of the jojo1981/jms-serializer-handlers package
4
 *
5
 * Copyright (c) 2019 Joost Nijhuis <jnijhuis81@gmail.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed in the root of the source code
9
 */
10
namespace Jojo1981\JmsSerializerHandlers;
11

12
use JMS\Serializer\Construction\ObjectConstructorInterface;
13
use JMS\Serializer\DeserializationContext;
14
use JMS\Serializer\Metadata\ClassMetadata;
15
use JMS\Serializer\Visitor\DeserializationVisitorInterface;
16
use Jojo1981\TypedCollection\Collection;
17
use Jojo1981\TypedCollection\Exception\CollectionException;
18
use ReflectionException;
19
use ReflectionProperty;
20

21
/**
22
 * @package Jojo1981\JmsSerializerHandlers
23
 */
24
final class TypedCollectionObjectConstructorDecorator implements ObjectConstructorInterface
25
{
26
    /** @var ObjectConstructorInterface */
27
    private ObjectConstructorInterface $objectConstructor;
28

29
    /**
30
     * @param ObjectConstructorInterface $objectConstructor
31
     */
32
    public function __construct(ObjectConstructorInterface $objectConstructor)
33
    {
34
        $this->objectConstructor = $objectConstructor;
145✔
35
    }
36

37
    /**
38
     * @param DeserializationVisitorInterface $visitor
39
     * @param ClassMetadata $metadata
40
     * @param mixed $data
41
     * @param array $type
42
     * @param DeserializationContext $context
43
     * @return object|null
44
     * @throws ReflectionException
45
     * @throws CollectionException
46
     */
47
    public function construct(
48
        DeserializationVisitorInterface $visitor,
49
        ClassMetadata $metadata,
50
        $data,
51
        array $type,
52
        DeserializationContext $context
53
    ): ?object {
54
        $object = $this->objectConstructor->construct($visitor, $metadata, $data, $type, $context);
65✔
55
        foreach ($metadata->propertyMetadata as $property) {
65✔
56
            if (null === $property->type) {
65✔
57
                continue;
×
58
            }
59

60
            $reflectionProperty = new ReflectionProperty($property->class, $property->name);
65✔
61
            $reflectionProperty->setAccessible(true);
65✔
62

63
            if (Collection::class === $property->type['name']) {
65✔
64
                $innerType = $property->type['params'][0]['name'];
25✔
65
                $reflectionProperty->setValue($object, new Collection($innerType));
25✔
66
            } elseif ('array' === $property->type['name']) {
65✔
67
                $reflectionProperty->setValue($object, []);
35✔
68
            } elseif ($property->skipWhenEmpty && (null !== $reflectionType = $reflectionProperty->getType()) && $reflectionType->allowsNull()) {
65✔
69
                $reflectionProperty->setValue($object, null);
×
70
            }
71
        }
72

73
        return $object;
65✔
74
    }
75
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc