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

api-platform / core / 19932181686

04 Dec 2025 02:20PM UTC coverage: 25.213% (-0.007%) from 25.22%
19932181686

push

github

web-flow
refactor(state): replace :property placeholder with properties (#7547)

fixes #7478

101 of 144 new or added lines in 18 files covered. (70.14%)

12 existing lines in 5 files now uncovered.

14565 of 57767 relevant lines covered (25.21%)

28.72 hits per line

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

0.0
/src/JsonApi/Filter/SparseFieldsetParameterProvider.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\JsonApi\Filter;
15

16
use ApiPlatform\Metadata\Operation;
17
use ApiPlatform\Metadata\Parameter;
18
use ApiPlatform\State\ParameterProviderInterface;
19
use Symfony\Component\Serializer\Normalizer\AbstractNormalizer;
20

21
final readonly class SparseFieldsetParameterProvider implements ParameterProviderInterface
22
{
23
    public function provide(Parameter $parameter, array $parameters = [], array $context = []): ?Operation
24
    {
25
        if (!($operation = $context['operation'] ?? null)) {
×
26
            return null;
×
27
        }
28

NEW
29
        $allowedProperties = $parameter->getProperties() ?? [];
×
30
        $value = $parameter->getValue();
×
31
        $normalizationContext = $operation->getNormalizationContext();
×
32

33
        if (!\is_array($value)) {
×
34
            return null;
×
35
        }
36

37
        $properties = [];
×
38
        $shortName = strtolower($operation->getShortName());
×
39
        foreach ($value as $resource => $fields) {
×
40
            if (strtolower($resource) === $shortName) {
×
41
                $p = &$properties;
×
42
            } else {
43
                $properties[$resource] = [];
×
44
                $p = &$properties[$resource];
×
45
            }
46

47
            foreach (explode(',', $fields) as $f) {
×
NEW
48
                if (\in_array($f, $allowedProperties, true)) {
×
49
                    $p[] = $f;
×
50
                }
51
            }
52
        }
53

54
        if (isset($normalizationContext[AbstractNormalizer::ATTRIBUTES])) {
×
55
            $properties = array_merge_recursive((array) $normalizationContext[AbstractNormalizer::ATTRIBUTES], $properties);
×
56
        }
57

58
        $normalizationContext[AbstractNormalizer::ATTRIBUTES] = $properties;
×
59

60
        return $operation->withNormalizationContext($normalizationContext);
×
61
    }
62
}
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