• 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

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

16
use ApiPlatform\Metadata\GraphQl\Operation as GraphQlOperation;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\Metadata\ResourceAccessCheckerInterface;
19
use ApiPlatform\State\ParameterNotFound;
20
use ApiPlatform\State\ProviderInterface;
21
use ApiPlatform\State\Util\ParameterParserTrait;
22
use ApiPlatform\Symfony\Security\Exception\AccessDeniedException;
23
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
24

25
/**
26
 * Loops over parameters to check parameter security.
27
 * Throws an exception if security is not granted.
28
 */
29
final class SecurityParameterProvider implements ProviderInterface
30
{
31
    use ParameterParserTrait;
32

33
    public function __construct(private readonly ProviderInterface $decorated, private readonly ?ResourceAccessCheckerInterface $resourceAccessChecker = null)
34
    {
UNCOV
35
    }
799✔
36

37
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
38
    {
UNCOV
39
        $body = $this->decorated->provide($operation, $uriVariables, $context);
799✔
UNCOV
40
        $request = $context['request'] ?? null;
794✔
41

UNCOV
42
        $operation = $request?->attributes->get('_api_operation') ?? $operation;
794✔
UNCOV
43
        foreach ($operation->getParameters() ?? [] as $parameter) {
794✔
UNCOV
44
            if (null === $security = $parameter->getSecurity()) {
347✔
UNCOV
45
                continue;
340✔
46
            }
47

UNCOV
48
            if (($v = $parameter->getValue()) instanceof ParameterNotFound) {
7✔
UNCOV
49
                continue;
6✔
50
            }
51

UNCOV
52
            $securityContext = [$parameter->getKey() => $v, 'object' => $body, 'operation' => $operation];
7✔
UNCOV
53
            if (!$this->resourceAccessChecker->isGranted($context['resource_class'], $security, $securityContext)) {
7✔
UNCOV
54
                throw $operation instanceof GraphQlOperation ? new AccessDeniedHttpException($parameter->getSecurityMessage() ?? 'Access Denied.') : new AccessDeniedException($parameter->getSecurityMessage() ?? 'Access Denied.');
3✔
55
            }
56
        }
57

UNCOV
58
        return $body;
792✔
59
    }
60
}
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