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

api-platform / core / 15955912273

29 Jun 2025 01:51PM UTC coverage: 22.057% (-0.03%) from 22.082%
15955912273

Pull #7249

github

web-flow
Merge d9904d788 into a42034dc3
Pull Request #7249: chore: solve some phpstan issues

0 of 9 new or added lines in 8 files covered. (0.0%)

11540 existing lines in 372 files now uncovered.

11522 of 52237 relevant lines covered (22.06%)

11.08 hits per line

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

94.59
/src/Symfony/Security/State/AccessCheckerProvider.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\Security\State;
15

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

26
/**
27
 * Allows access based on the ApiPlatform\Metadata\ResourceAccessCheckerInterface.
28
 * This implementation covers GraphQl and HTTP.
29
 *
30
 * @see ResourceAccessCheckerInterface
31
 */
32
final class AccessCheckerProvider implements ProviderInterface
33
{
34
    public function __construct(private readonly ProviderInterface $decorated, private readonly ResourceAccessCheckerInterface $resourceAccessChecker, private readonly ?string $event = null)
35
    {
UNCOV
36
    }
257✔
37

38
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
39
    {
UNCOV
40
        switch ($this->event) {
242✔
UNCOV
41
            case 'post_denormalize':
242✔
UNCOV
42
                $isGranted = $operation->getSecurityPostDenormalize();
23✔
UNCOV
43
                $message = $operation->getSecurityPostDenormalizeMessage();
23✔
UNCOV
44
                break;
23✔
UNCOV
45
            case 'post_validate':
241✔
UNCOV
46
                $isGranted = $operation->getSecurityPostValidation();
231✔
UNCOV
47
                $message = $operation->getSecurityPostValidationMessage();
231✔
UNCOV
48
                break;
231✔
UNCOV
49
            case 'after_resolver':
240✔
UNCOV
50
                if (!$operation instanceof GraphQlOperation) {
13✔
51
                    throw new RuntimeException('Not a graphql operation');
×
52
                }
53

UNCOV
54
                $isGranted = $operation->getSecurityAfterResolver();
13✔
UNCOV
55
                $message = $operation->getSecurityMessageAfterResolver();
13✔
UNCOV
56
                break;
13✔
57
            default:
UNCOV
58
                $isGranted = $operation->getSecurity();
240✔
UNCOV
59
                $message = $operation->getSecurityMessage();
240✔
60
        }
61

UNCOV
62
        $body = $this->decorated->provide($operation, $uriVariables, $context);
242✔
UNCOV
63
        if (null === $isGranted) {
241✔
UNCOV
64
            return $body;
233✔
65
        }
66

67
        // On a GraphQl QueryCollection we want to perform security stage only on the top-level query
UNCOV
68
        if ($operation instanceof QueryCollection && null !== ($context['source'] ?? null)) {
13✔
69
            return $body;
×
70
        }
71

UNCOV
72
        if ($operation instanceof HttpOperation) {
13✔
UNCOV
73
            $request = $context['request'] ?? null;
8✔
74

UNCOV
75
            $resourceAccessCheckerContext = [
8✔
UNCOV
76
                'object' => $body,
8✔
UNCOV
77
                'previous_object' => $request?->attributes->get('previous_data'),
8✔
UNCOV
78
                'request' => $request,
8✔
UNCOV
79
            ];
8✔
80
        } else {
UNCOV
81
            $resourceAccessCheckerContext = [
5✔
UNCOV
82
                'object' => $body,
5✔
UNCOV
83
                'previous_object' => $context['graphql_context']['previous_object'] ?? null,
5✔
UNCOV
84
            ];
5✔
85
        }
86

UNCOV
87
        if (!$this->resourceAccessChecker->isGranted($operation->getClass(), $isGranted, $resourceAccessCheckerContext)) {
13✔
UNCOV
88
            $operation instanceof GraphQlOperation ? throw new AccessDeniedHttpException($message ?? 'Access Denied.') : throw new AccessDeniedException($message ?? 'Access Denied.');
5✔
89
        }
90

UNCOV
91
        return $body;
8✔
92
    }
93
}
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