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

api-platform / core / 17545966872

08 Sep 2025 09:18AM UTC coverage: 22.312% (-0.3%) from 22.604%
17545966872

push

github

web-flow
fix(metadata): wrong method name in resource mutator

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

12092 existing lines in 401 files now uncovered.

11916 of 53406 relevant lines covered (22.31%)

13.09 hits per line

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

100.0
/src/Serializer/State/JsonStreamerProcessor.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\Serializer\State;
15

16
use ApiPlatform\Metadata\CollectionOperationInterface;
17
use ApiPlatform\Metadata\Error;
18
use ApiPlatform\Metadata\HttpOperation;
19
use ApiPlatform\Metadata\IriConverterInterface;
20
use ApiPlatform\Metadata\Operation;
21
use ApiPlatform\Metadata\Operation\Factory\OperationMetadataFactoryInterface;
22
use ApiPlatform\Metadata\ResourceClassResolverInterface;
23
use ApiPlatform\State\ProcessorInterface;
24
use ApiPlatform\State\Util\HttpResponseHeadersTrait;
25
use ApiPlatform\State\Util\HttpResponseStatusTrait;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\HttpFoundation\StreamedResponse;
28
use Symfony\Component\JsonStreamer\StreamWriterInterface;
29
use Symfony\Component\TypeInfo\Type;
30

31
/**
32
 * @implements ProcessorInterface<mixed,mixed>
33
 */
34
final class JsonStreamerProcessor implements ProcessorInterface
35
{
36
    use HttpResponseHeadersTrait;
37
    use HttpResponseStatusTrait;
38

39
    /**
40
     * @param ProcessorInterface<mixed,mixed>|null       $processor
41
     * @param StreamWriterInterface<array<string,mixed>> $jsonStreamer
42
     */
43
    public function __construct(
44
        private readonly ?ProcessorInterface $processor,
45
        private readonly StreamWriterInterface $jsonStreamer,
46
        ?IriConverterInterface $iriConverter = null,
47
        ?ResourceClassResolverInterface $resourceClassResolver = null,
48
        ?OperationMetadataFactoryInterface $operationMetadataFactory = null,
49
    ) {
UNCOV
50
        $this->resourceClassResolver = $resourceClassResolver;
312✔
UNCOV
51
        $this->iriConverter = $iriConverter;
312✔
UNCOV
52
        $this->operationMetadataFactory = $operationMetadataFactory;
312✔
53
    }
54

55
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
56
    {
57
        if (
UNCOV
58
            $operation instanceof Error
311✔
UNCOV
59
            || $data instanceof Response
311✔
UNCOV
60
            || !$operation instanceof HttpOperation
311✔
UNCOV
61
            || !($request = $context['request'] ?? null)
311✔
UNCOV
62
            || !$operation->getJsonStream()
311✔
UNCOV
63
            || 'json' !== $request->getRequestFormat()
311✔
64
        ) {
UNCOV
65
            return $this->processor?->process($data, $operation, $uriVariables, $context);
308✔
66
        }
67

UNCOV
68
        if ($operation instanceof CollectionOperationInterface) {
3✔
UNCOV
69
            $data = $this->jsonStreamer->write(
1✔
UNCOV
70
                $data,
1✔
UNCOV
71
                Type::list(Type::object($operation->getClass())),
1✔
UNCOV
72
                ['data' => $data, 'operation' => $operation],
1✔
UNCOV
73
            );
1✔
74
        } else {
UNCOV
75
            $data = $this->jsonStreamer->write(
2✔
UNCOV
76
                $data,
2✔
UNCOV
77
                Type::object($operation->getClass()),
2✔
UNCOV
78
                ['data' => $data, 'operation' => $operation],
2✔
UNCOV
79
            );
2✔
80
        }
81

82
        /** @var iterable<string> $data */
UNCOV
83
        $response = new StreamedResponse(
3✔
UNCOV
84
            $data,
3✔
UNCOV
85
            $this->getStatus($request, $operation, $context),
3✔
UNCOV
86
            $this->getHeaders($request, $operation, $context)
3✔
UNCOV
87
        );
3✔
88

UNCOV
89
        return $this->processor ? $this->processor->process($response, $operation, $uriVariables, $context) : $response;
3✔
90
    }
91
}
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