Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/Form/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public function validate(array $values): void
$validator = new Validator;
$validator->validate($values, $this->toJsonSchema(), Constraint::CHECK_MODE_TYPE_CAST);
if (!$validator->isValid()) {
$errorMessages = array_map(
fn ($error) => "[{$error['property']}] {$error['message']}",
$validator->getErrors(),
);
throw new FormValidationException("Form validation failed", $validator->getErrors());
}
}
Expand Down
12 changes: 5 additions & 7 deletions src/Form/FormElementCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,11 @@ public function getRequired(): array
public function getValues(): array
{
return array_filter(
Arr::collapse(
Arr::map(
(array) $this,
static fn (FormElement $formElement) => [
$formElement->name => $formElement->value(),
],
),
Arr::mapWithKeys(
(array) $this,
static fn (FormElement $formElement) => [
$formElement->name => $formElement->value(),
],
),
);
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Form/FormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,12 @@ public function test_it_converts_to_json_schema(): void
public function test_it_gets_values(): void
{
$text = new Text(
name: 'name_1',
name: '1001',
label: 'Label 1',
value: 'Initial text',
);
$checkbox = new Checkbox(
name: 'name_2',
name: '1002',
label: 'Label 2',
value: true,
);
Expand Down Expand Up @@ -238,11 +238,11 @@ public function test_it_gets_values(): void
);

assertEquals([
'name_1' => 'Initial text',
'name_2' => true,
1001 => 'Initial text',
1002 => true,
'name_4' => [
'name_1' => 'Initial text',
'name_2' => true,
1001 => 'Initial text',
1002 => true,
],
], $form->getValues());
}
Expand Down