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

GollumSF / rest-bundle / 23707748905

29 Mar 2026 11:09AM UTC coverage: 99.281% (-0.5%) from 99.815%
23707748905

push

github

Smeagolworms4
Fix Post resolver

19 of 21 new or added lines in 2 files covered. (90.48%)

1 existing line in 1 file now uncovered.

552 of 556 relevant lines covered (99.28%)

22.41 hits per line

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

96.3
/src/Serializer/Normalizer/DoctrineObjectDenormalizerTrait.php
1
<?php
2

3
namespace GollumSF\RestBundle\Serializer\Normalizer;
4

5
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
6

7
trait DoctrineObjectDenormalizerTrait {
8

9
        /** @var RecursiveObjectNormalizer */
10
        private $recursiveObjectNormalizer;
11

12
        /** @var array */
13
        private $cache = [];
14

15
        public function __construct(
16
                DenormalizerInterface $recursiveObjectNormalizer
17
        ) {
18
                $this->recursiveObjectNormalizer = $recursiveObjectNormalizer;
54✔
19
        }
20

21
        public function denormalizeImplement($data, string $class, ?string $format = null, array $context = []) {
22

23
                if (is_null($data)) {
30✔
24
                        return null;
1✔
25
                }
26

27
                if (isset($context['object_to_populate'])) {
29✔
28
                        return $this->recursiveObjectNormalizer->denormalize($data, $class, $format, $context);
20✔
29
                }
30

31
                $em = $this->getEntityManagerForClass($class);
19✔
32
                $metadata = $em->getClassMetadata($class);
19✔
33

34
                $ids = $metadata->getIdentifier();
19✔
35
                if (empty($ids)) {
19✔
36
                        return $this->recursiveObjectNormalizer->denormalize($data, $class, $format, $context);
1✔
37
                }
38

39
                $ctriteria = [];
18✔
40
                $hasId = false;
18✔
41
                foreach ($ids as $id) {
18✔
42
                        $value = array_key_exists($id, $data) ? $data[$id] : null;
18✔
43
                        $ctriteria[$id] = $value;
18✔
44
                        if ($value !== null && $value !== '') {
18✔
45
                                $hasId = true;
3✔
46
                        }
47
                }
48

49
                if (!$hasId) {
18✔
50
                        // No identifiers provided — create new entity (POST creation)
51
                        return $this->recursiveObjectNormalizer->denormalize($data, $class, $format, $context);
17✔
52
                }
53

54
                $entity = $this->getEntityRepositoryForClass($class)->findOneBy($ctriteria);
3✔
55
                if ($entity) {
3✔
56
                        $context['object_to_populate'] = $entity;
3✔
57
                        return $this->recursiveObjectNormalizer->denormalize($data, $class, $format, $context);
3✔
58
                }
59

60
                // Id provided but entity not found
NEW
61
                return null;
×
62
        }
63

64
        public function supportsDenormalizationImplement($data, string $type, ?string $format = null): bool {
65
                if (!array_key_exists($type, $this->cache)) {
36✔
66
                        $this->cache[$type] = class_exists($type) && $this->isEntity($type) && (is_array($data) || is_null($data));
36✔
67
                }
68
                return $this->cache[$type];
36✔
69
        }
70
}
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