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

api-platform / core / 15133993414

20 May 2025 09:30AM UTC coverage: 26.313% (-1.2%) from 27.493%
15133993414

Pull #7161

github

web-flow
Merge e2c03d45f into 5459ba375
Pull Request #7161: fix(metadata): infer parameter string type from schema

0 of 2 new or added lines in 1 file covered. (0.0%)

11019 existing lines in 363 files now uncovered.

12898 of 49018 relevant lines covered (26.31%)

34.33 hits per line

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

84.62
/src/State/Processor/SerializeProcessor.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\State\Processor;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\State\ProcessorInterface;
18
use ApiPlatform\State\ResourceList;
19
use ApiPlatform\State\SerializerContextBuilderInterface;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer;
22
use Symfony\Component\Serializer\SerializerInterface;
23
use Symfony\Component\WebLink\GenericLinkProvider;
24
use Symfony\Component\WebLink\Link;
25

26
/**
27
 * Serializes data.
28
 *
29
 * @template T1
30
 * @template T2
31
 *
32
 * @implements ProcessorInterface<T1, T2>
33
 *
34
 * @author Kévin Dunglas <dunglas@gmail.com>
35
 */
36
final class SerializeProcessor implements ProcessorInterface
37
{
38
    /**
39
     * @param ProcessorInterface<mixed, mixed>|null $processor
40
     */
41
    public function __construct(private readonly ?ProcessorInterface $processor, private readonly SerializerInterface $serializer, private readonly SerializerContextBuilderInterface $serializerContextBuilder)
42
    {
UNCOV
43
    }
799✔
44

45
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
46
    {
UNCOV
47
        if ($data instanceof Response || !$operation->canSerialize() || !($request = $context['request'] ?? null)) {
792✔
UNCOV
48
            return $this->processor ? $this->processor->process($data, $operation, $uriVariables, $context) : $data;
23✔
49
        }
50

51
        // @see ApiPlatform\State\Processor\RespondProcessor
UNCOV
52
        $context['original_data'] = $data;
771✔
53

UNCOV
54
        $class = $operation->getClass();
771✔
UNCOV
55
        $serializerContext = $this->serializerContextBuilder->createFromRequest($request, true, [
771✔
UNCOV
56
            'resource_class' => $class,
771✔
UNCOV
57
            'operation' => $operation,
771✔
UNCOV
58
        ]);
771✔
59

UNCOV
60
        $serializerContext['uri_variables'] = $uriVariables;
771✔
61

UNCOV
62
        if (isset($serializerContext['output']) && \array_key_exists('class', $serializerContext['output']) && null === $serializerContext['output']['class']) {
771✔
63
            return $this->processor ? $this->processor->process(null, $operation, $uriVariables, $context) : null;
3✔
64
        }
65

UNCOV
66
        $resources = new ResourceList();
768✔
UNCOV
67
        $serializerContext['resources'] = &$resources;
768✔
UNCOV
68
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources';
768✔
69

UNCOV
70
        $resourcesToPush = new ResourceList();
768✔
UNCOV
71
        $serializerContext['resources_to_push'] = &$resourcesToPush;
768✔
UNCOV
72
        $serializerContext[AbstractObjectNormalizer::EXCLUDE_FROM_CACHE_KEY][] = 'resources_to_push';
768✔
73

UNCOV
74
        $serialized = $this->serializer->serialize($data, $request->getRequestFormat(), $serializerContext);
768✔
UNCOV
75
        $request->attributes->set('_resources', $request->attributes->get('_resources', []) + (array) $resources);
768✔
UNCOV
76
        if (\count($resourcesToPush)) {
768✔
77
            $linkProvider = $request->attributes->get('_api_platform_links', new GenericLinkProvider());
×
78
            foreach ($resourcesToPush as $resourceToPush) {
×
79
                $linkProvider = $linkProvider->withLink((new Link('preload', $resourceToPush))->withAttribute('as', 'fetch'));
×
80
            }
81
            $request->attributes->set('_api_platform_links', $linkProvider);
×
82
        }
83

UNCOV
84
        return $this->processor ? $this->processor->process($serialized, $operation, $uriVariables, $context) : $serialized;
768✔
85
    }
86
}
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

© 2025 Coveralls, Inc