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

api-platform / core / 10014117656

19 Jul 2024 08:44PM UTC coverage: 7.856% (-56.3%) from 64.185%
10014117656

push

github

soyuka
Merge branch 'sf/remove-flag'

0 of 527 new or added lines in 83 files covered. (0.0%)

10505 existing lines in 362 files now uncovered.

12705 of 161727 relevant lines covered (7.86%)

26.85 hits per line

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

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

16
use ApiPlatform\Metadata\Error as ErrorOperation;
17
use ApiPlatform\Metadata\ErrorResource;
18
use ApiPlatform\Metadata\Exception\HttpExceptionInterface;
19
use ApiPlatform\Metadata\Exception\ProblemExceptionInterface;
20
use ApiPlatform\Metadata\Exception\RuntimeException;
21
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface as SymfonyHttpExceptionInterface;
22
use Symfony\Component\Serializer\Annotation\Groups;
23
use Symfony\Component\Serializer\Annotation\SerializedName;
24
use Symfony\Component\WebLink\Link;
25

26
/**
27
 * Thrown when a validation error occurs.
28
 *
29
 * @author Kévin Dunglas <dunglas@gmail.com>
30
 */
31
#[ErrorResource(
32
    uriTemplate: '/validation_errors/{id}',
×
33
    status: 422,
×
34
    openapi: false,
×
35
    uriVariables: ['id'],
×
36
    shortName: 'ValidationError',
×
37
    operations: [
×
38
        new ErrorOperation(
×
39
            name: '_api_validation_errors_problem',
×
40
            outputFormats: ['json' => ['application/problem+json']],
×
41
            normalizationContext: ['groups' => ['json'],
×
42
                'skip_null_values' => true,
×
43
            ],
×
44
            uriTemplate: '/validation_errors/{id}'
×
45
        ),
×
46
        new ErrorOperation(
×
47
            name: '_api_validation_errors_hydra',
×
48
            outputFormats: ['jsonld' => ['application/problem+json']],
×
49
            links: [new Link(rel: 'http://www.w3.org/ns/json-ld#error', href: 'http://www.w3.org/ns/hydra/error')],
×
50
            normalizationContext: [
×
51
                'groups' => ['jsonld'],
×
52
                'skip_null_values' => true,
×
53
            ],
×
54
            uriTemplate: '/validation_errors/{id}.jsonld'
×
55
        ),
×
56
        new ErrorOperation(
×
57
            name: '_api_validation_errors_jsonapi',
×
58
            outputFormats: ['jsonapi' => ['application/vnd.api+json']],
×
NEW
59
            normalizationContext: [
×
NEW
60
                'groups' => ['jsonapi'],
×
NEW
61
                'skip_null_values' => true,
×
NEW
62
            ],
×
63
            uriTemplate: '/validation_errors/{id}.jsonapi'
×
64
        ),
×
65
    ],
×
66
    graphQlOperations: []
×
67
)]
×
68
class ValidationError extends RuntimeException implements \Stringable, ProblemExceptionInterface, HttpExceptionInterface, SymfonyHttpExceptionInterface
69
{
70
    private int $status = 422;
71
    private string $id;
72

73
    /**
74
     * @param array<int, array{propertyPath: string, message: string, code?: string}> $violations
75
     */
76
    public function __construct(string $message = '', mixed $code = null, ?\Throwable $previous = null, protected array $violations = [])
77
    {
78
        $this->id = (string) $code;
×
79
        $this->setDetail($message);
×
80
        parent::__construct($message ?: $this->__toString(), 422, $previous);
×
81
    }
82

83
    public function getId(): string
84
    {
85
        return $this->id;
×
86
    }
87

88
    #[SerializedName('description')]
89
    #[Groups(['jsonapi', 'jsonld', 'json'])]
90
    public function getDescription(): string
91
    {
92
        return $this->detail;
×
93
    }
94

95
    #[Groups(['jsonld', 'json'])]
96
    public function getType(): string
97
    {
98
        return '/validation_errors/'.$this->id;
×
99
    }
100

101
    #[Groups(['jsonld', 'json'])]
102
    public function getTitle(): ?string
103
    {
104
        return 'Validation Error';
×
105
    }
106

107
    #[Groups(['jsonld', 'json'])]
108
    private string $detail;
109

110
    public function getDetail(): ?string
111
    {
112
        return $this->detail;
×
113
    }
114

115
    public function setDetail(string $detail): void
116
    {
117
        $this->detail = $detail;
×
118
    }
119

120
    #[Groups(['jsonld', 'json'])]
121
    public function getStatus(): ?int
122
    {
123
        return $this->status;
×
124
    }
125

126
    public function setStatus(int $status): void
127
    {
128
        $this->status = $status;
×
129
    }
130

131
    #[Groups(['jsonld', 'json'])]
132
    public function getInstance(): ?string
133
    {
134
        return null;
×
135
    }
136

137
    /**
138
     * @return array<int,array{propertyPath:string,message:string,code?:string}>
139
     */
140
    #[SerializedName('violations')]
141
    #[Groups(['json', 'jsonld'])]
142
    public function getViolations(): array
143
    {
144
        return $this->violations;
×
145
    }
146

147
    public function getStatusCode(): int
148
    {
149
        return $this->status;
×
150
    }
151

152
    /**
153
     * @return array<string, string>
154
     */
155
    public function getHeaders(): array
156
    {
157
        return [];
×
158
    }
159
}
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