Skip to content

Commit

Permalink
Add type check to ensure property is an array before looping through it
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jan 18, 2023
1 parent 5bb0c74 commit 66feecf
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions packages/publications/src/Actions/ValidatesPublicationSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,22 @@ public function __invoke(): static
// TODO warn if pageSize is less than 0 (as that equals no pagination)?
foreach ($schema->fields as $field) {
// TODO check tag group exists?
$this->fieldValidators->add(validator([
'type' => $field->type ?? null,
'name' => $field->name ?? null,
'rules' => $field->rules ?? null,
'tagGroup' => $field->tagGroup ?? null,
], [
'type' => 'required|string',
'name' => 'required|string',
'rules' => 'nullable|array',
'tagGroup' => 'nullable|string',
]));
if (is_array($schema->fields)) {
foreach ($schema->fields as $field) {
// TODO check tag group exists?
$this->fieldValidators->add(validator([
'type' => $field->type ?? null,
'name' => $field->name ?? null,
'rules' => $field->rules ?? null,
'tagGroup' => $field->tagGroup ?? null,
], [
'type' => 'required|string',
'name' => 'required|string',
'rules' => 'nullable|array',
'tagGroup' => 'nullable|string',
]));
}
}

return $this;
Expand Down

0 comments on commit 66feecf

Please sign in to comment.