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

api-platform / core / 8100440090

29 Feb 2024 05:54PM UTC coverage: 57.09% (+0.2%) from 56.922%
8100440090

Pull #6138

github

web-flow
chore(deps): bump codecov/codecov-action from 3 to 4

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3 to 4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/codecov/codecov-action/compare/v3...v4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #6138: chore(deps): bump codecov/codecov-action from 3 to 4

9538 of 16707 relevant lines covered (57.09%)

30.81 hits per line

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

41.18
/src/Symfony/EventListener/QueryParameterValidateListener.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\Symfony\EventListener;
15

16
use ApiPlatform\Doctrine\Odm\State\Options as ODMOptions;
17
use ApiPlatform\Doctrine\Orm\State\Options;
18
use ApiPlatform\Metadata\CollectionOperationInterface;
19
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
20
use ApiPlatform\ParameterValidator\ParameterValidator;
21
use ApiPlatform\State\ProviderInterface;
22
use ApiPlatform\State\Util\OperationRequestInitiatorTrait;
23
use ApiPlatform\State\Util\RequestParser;
24
use ApiPlatform\Symfony\Util\RequestAttributesExtractor;
25
use Symfony\Component\HttpKernel\Event\RequestEvent;
26

27
/**
28
 * Validates query parameters depending on filter description.
29
 *
30
 * @author Julien Deniau <julien.deniau@mapado.com>
31
 */
32
final class QueryParameterValidateListener
33
{
34
    use OperationRequestInitiatorTrait;
35

36
    public const OPERATION_ATTRIBUTE_KEY = 'query_parameter_validate';
37
    private ?ParameterValidator $queryParameterValidator = null;
38
    private ?ProviderInterface $provider = null;
39

40
    public function __construct($queryParameterValidator, ?ResourceMetadataCollectionFactoryInterface $resourceMetadataCollectionFactory = null)
41
    {
42
        if ($queryParameterValidator instanceof ProviderInterface) {
28✔
43
            $this->provider = $queryParameterValidator;
×
44
        } else {
45
            trigger_deprecation('api-platform/core', '3.3', 'Use a "%s" as first argument in "%s" instead of "%s".', ProviderInterface::class, self::class, ParameterValidator::class);
28✔
46
            $this->queryParameterValidator = $queryParameterValidator;
28✔
47
        }
48

49
        $this->resourceMetadataCollectionFactory = $resourceMetadataCollectionFactory;
28✔
50
    }
51

52
    public function onKernelRequest(RequestEvent $event): void
53
    {
54
        $request = $event->getRequest();
28✔
55
        $operation = $this->initializeOperation($request);
28✔
56

57
        if ($operation && $this->provider instanceof ProviderInterface) {
28✔
58
            if (null === $operation->getQueryParameterValidationEnabled()) {
×
59
                $operation = $operation->withQueryParameterValidationEnabled($request->isMethodSafe() && 'GET' === $request->getMethod() && $operation instanceof CollectionOperationInterface);
×
60
            }
61

62
            $this->provider->provide($operation, $request->attributes->get('_api_uri_variables') ?? [], [
×
63
                'request' => $request,
×
64
                'uri_variables' => $request->attributes->get('_api_uri_variables') ?? [],
×
65
                'resource_class' => $operation->getClass(),
×
66
            ]);
×
67

68
            return;
×
69
        }
70

71
        if (
72
            !$request->isMethodSafe()
28✔
73
            || !($attributes = RequestAttributesExtractor::extractAttributes($request))
28✔
74
            || 'GET' !== $request->getMethod()
28✔
75
            || $request->attributes->get('_api_platform_disable_listeners')
28✔
76
        ) {
77
            return;
17✔
78
        }
79

80
        if ('api_platform.symfony.main_controller' === $operation?->getController()) {
14✔
81
            return;
14✔
82
        }
83

84
        if (!($operation?->getQueryParameterValidationEnabled() ?? true) || !$operation instanceof CollectionOperationInterface) {
×
85
            return;
×
86
        }
87

88
        $queryString = RequestParser::getQueryString($request);
×
89
        $queryParameters = $queryString ? RequestParser::parseRequestParams($queryString) : [];
×
90

91
        $class = $attributes['resource_class'];
×
92

93
        if ($options = $operation->getStateOptions()) {
×
94
            if ($options instanceof Options && $options->getEntityClass()) {
×
95
                $class = $options->getEntityClass();
×
96
            }
97

98
            if ($options instanceof ODMOptions && $options->getDocumentClass()) {
×
99
                $class = $options->getDocumentClass();
×
100
            }
101
        }
102

103
        $this->queryParameterValidator->validateFilters($class, $operation->getFilters() ?? [], $queryParameters);
×
104
    }
105
}
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