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

api-platform / core / 10904989553

17 Sep 2024 01:21PM UTC coverage: 7.547% (-0.1%) from 7.684%
10904989553

push

github

web-flow
fix(laravel): call authorize on delete but not validation (#6618)

0 of 15 new or added lines in 5 files covered. (0.0%)

3 existing lines in 1 file now uncovered.

12444 of 164877 relevant lines covered (7.55%)

22.93 hits per line

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

0.0
/src/Laravel/State/ValidateProvider.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\Laravel\State;
15

16
use ApiPlatform\Metadata\Error;
17
use ApiPlatform\Metadata\Operation;
18
use ApiPlatform\State\ProviderInterface;
19
use Illuminate\Contracts\Foundation\Application;
20
use Illuminate\Foundation\Http\FormRequest;
21
use Illuminate\Support\Facades\Validator;
22
use Illuminate\Validation\ValidationException;
23

24
/**
25
 * @implements ProviderInterface<object>
26
 */
27
final class ValidateProvider implements ProviderInterface
28
{
29
    use ValidationErrorTrait;
30

31
    /**
32
     * @param ProviderInterface<object> $inner
33
     */
34
    public function __construct(
35
        private readonly ProviderInterface $inner,
36
        private readonly Application $app,
37
    ) {
38
    }
×
39

40
    public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
41
    {
42
        $request = $context['request'];
×
43
        $body = $this->inner->provide($operation, $uriVariables, $context);
×
44

NEW
45
        if ($operation instanceof Error) {
×
46
            return $body;
×
47
        }
48

49
        $rules = $operation->getRules();
×
50
        if (\is_callable($rules)) {
×
51
            $rules = $rules();
×
52
        }
53

54
        if (\is_string($rules) && is_a($rules, FormRequest::class, true)) {
×
55
            try {
56
                // this also throws an AuthorizationException
UNCOV
57
                $this->app->make($rules);
×
UNCOV
58
            } catch (ValidationException $e) { // @phpstan-ignore-line make->($rules) may throw this
×
NEW
59
                if (!$operation->canValidate()) {
×
NEW
60
                    return $body;
×
61
                }
62

UNCOV
63
                throw $this->getValidationError($e->validator, $e);
×
64
            }
65

66
            return $body;
×
67
        }
68

NEW
69
        if (!$operation->canValidate()) {
×
NEW
70
            return $body;
×
71
        }
72

73
        if (!\is_array($rules)) {
×
74
            return $body;
×
75
        }
76

77
        $validator = Validator::make($request->request->all(), $rules);
×
78
        if ($validator->fails()) {
×
79
            throw $this->getValidationError($validator, new ValidationException($validator));
×
80
        }
81

82
        return $body;
×
83
    }
84
}
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