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

api-platform / core / 10814494863

11 Sep 2024 03:11PM UTC coverage: 7.008% (-0.7%) from 7.679%
10814494863

push

github

web-flow
fix(state): remove resource_class change (#6607)

11516 of 164321 relevant lines covered (7.01%)

22.85 hits per line

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

84.62
/src/Serializer/SerializerFilterContextBuilder.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;
15

16
use ApiPlatform\Metadata\Exception\RuntimeException;
17
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
18
use ApiPlatform\Metadata\Util\AttributesExtractor;
19
use ApiPlatform\Serializer\Filter\FilterInterface;
20
use Psr\Container\ContainerInterface;
21
use Symfony\Component\HttpFoundation\Request;
22

23
/**
24
 * {@inheritdoc}
25
 *
26
 * @author Baptiste Meyer <baptiste.meyer@gmail.com>
27
 */
28
final class SerializerFilterContextBuilder implements SerializerContextBuilderInterface
29
{
30
    public function __construct(private readonly ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory, private readonly ContainerInterface $filterLocator, private readonly SerializerContextBuilderInterface $decorated)
31
    {
32
    }
1,851✔
33

34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function createFromRequest(Request $request, bool $normalization, ?array $attributes = null): array
38
    {
39
        if (null === $attributes && !$attributes = AttributesExtractor::extractAttributes($request->attributes->all())) {
1,842✔
40
            throw new RuntimeException('Request attributes are not valid.');
×
41
        }
42

43
        $context = $this->decorated->createFromRequest($request, $normalization, $attributes);
1,842✔
44

45
        if (!($operation = $context['operation'] ?? null)) {
1,842✔
46
            $operation = $this->resourceMetadataCollectionFactory->create($attributes['resource_class'])->getOperation($attributes['operation_name'] ?? null);
×
47
        }
48

49
        $resourceFilters = $operation->getFilters();
1,842✔
50

51
        if (!$resourceFilters) {
1,842✔
52
            return $context;
1,150✔
53
        }
54

55
        foreach ($resourceFilters as $filterId) {
768✔
56
            if ($this->filterLocator->has($filterId) && ($filter = $this->filterLocator->get($filterId)) instanceof FilterInterface) {
768✔
57
                $filter->apply($request, $normalization, $attributes, $context);
583✔
58
            }
59
        }
60

61
        return $context;
768✔
62
    }
63
}
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