Skip to content

Commit

Permalink
Extract method to cast validated boolean result to bool
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Dec 28, 2022
1 parent c2790fe commit f4a5887
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,14 @@ protected function collectFieldData(): Collection
return $data;
}

protected function captureFieldInput(PublicationField $field): string|array|null
protected function captureFieldInput(PublicationField $field): bool|string|array|null
{
return match ($field->type) {
PublicationFieldTypes::Text => $this->captureTextFieldInput($field),
PublicationFieldTypes::Array => $this->captureArrayFieldInput($field),
PublicationFieldTypes::Image => $this->captureImageFieldInput($field),
PublicationFieldTypes::Tag => $this->captureTagFieldInput($field),
PublicationFieldTypes::Boolean => $this->captureBooleanFieldInput($field),
default => $this->askWithValidation($field->name, "Enter data for field </>[<comment>$field->name</comment>]", $field->type->rules()),
};
}
Expand Down Expand Up @@ -171,6 +172,11 @@ protected function captureTagFieldInput(PublicationField $field): array|string|n
);
}

protected function captureBooleanFieldInput(PublicationField $field): bool
{
return (bool) $this->askWithValidation($field->name, "Enter data for field </>[<comment>$field->name</comment>]", $field->type->rules());
}

/** @return null */
protected function handleEmptyOptionsCollection(PublicationField $field, string $type, string $message)
{
Expand Down

0 comments on commit f4a5887

Please sign in to comment.