Enforce request validation style rules
linter / quality (pull_request) Successful in 2m28s
tests / ci (8.4) (pull_request) Successful in 1m22s

This commit is contained in:
2026-04-11 19:44:21 +02:00
parent 97b188e942
commit 73cee8178f
7 changed files with 101 additions and 72 deletions
@@ -71,14 +71,16 @@ class UpdateProjectTicketRequest extends FormRequest
{
return [
function (Validator $validator): void {
/** @var array<string, mixed> $validated */
$validated = $this->validated();
/** @var Project $project */
$project = $this->route('project');
/** @var Ticket $ticket */
$ticket = $this->route('ticket');
$parentTicketId = $this->input('parent_ticket_id');
$parentTicketId = is_numeric($parentTicketId) ? (int) $parentTicketId : null;
$parentTicketId = Arr::get($validated, 'parent_ticket_id');
if ($parentTicketId !== null) {
if ($parentTicketId === $ticket->id) {
@@ -105,12 +107,10 @@ class UpdateProjectTicketRequest extends FormRequest
}
}
$requestedTicketTypeId = $this->input('ticket_type_id');
$requestedTicketType = is_numeric($requestedTicketTypeId)
? TicketType::query()
->where('project_id', $project->id)
->find((int) $requestedTicketTypeId)
: null;
$requestedTicketTypeId = Arr::get($validated, 'ticket_type_id');
$requestedTicketType = TicketType::query()
->where('project_id', $project->id)
->find($requestedTicketTypeId);
if (
$requestedTicketType?->system_key !== 'parent'
@@ -119,61 +119,13 @@ class UpdateProjectTicketRequest extends FormRequest
$validator->errors()->add('ticket_type_id', 'Tickets with child tickets must keep a Parent type.');
}
if ($this->boolean('is_blocked') && blank($this->input('blocked_comment'))) {
if (Arr::get($validated, 'is_blocked', false) && blank(Arr::get($validated, 'blocked_comment'))) {
$validator->errors()->add('blocked_comment', 'Blocked tickets require a blocker comment.');
}
},
];
}
/**
* @return array{
* acceptance_criteria: string|null,
* blocked_comment: string|null,
* description: string|null,
* is_blocked: bool,
* parent_ticket_id: int|null,
* ticket_priority_id: int,
* ticket_type_id: int,
* title: string
* }
*/
public function ticketAttributes(): array
{
/** @var array{
* acceptance_criteria: string|null,
* blocked_comment: string|null,
* description: string|null,
* is_blocked: bool,
* parent_ticket_id: int|null,
* ticket_priority_id: int,
* ticket_type_id: int,
* title: string
* } $attributes
*/
$attributes = array_merge(
[
'acceptance_criteria' => null,
'blocked_comment' => null,
'description' => null,
'is_blocked' => false,
'parent_ticket_id' => null,
],
Arr::only($this->validated(), [
'acceptance_criteria',
'blocked_comment',
'description',
'is_blocked',
'parent_ticket_id',
'ticket_priority_id',
'ticket_type_id',
'title',
]),
);
return $attributes;
}
private function createsCycle(Ticket $ticket, Ticket $candidateParent): bool
{
$currentParent = $candidateParent;