Skip to content

Commit 3c8fc11

Browse files
committed
Don't cast form->data to array if it's not iterable
1 parent c304e46 commit 3c8fc11

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Bridge/Interaction/CollectionInteractor.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,19 @@ public function interactWith(
5050
throw new CanNotInteractWithForm('Expected a "collection" form');
5151
}
5252

53-
if (!$form->getConfig()->getOption('allow_add') && empty($form->getData())) {
53+
$data = $form->getData();
54+
if (!$form->getConfig()->getOption('allow_add') && empty($data)) {
5455
throw new FormNotReadyForInteraction(
5556
'The "collection" form should have the option "allow_add" or have existing entries'
5657
);
5758
}
5859

60+
if (!is_iterable($data)) {
61+
throw new FormNotReadyForInteraction(
62+
'The "collection" form must be iterable'
63+
);
64+
}
65+
5966
$this->printHeader($form, $output);
6067

6168
$submittedData = [];
@@ -66,7 +73,7 @@ public function interactWith(
6673
return $this->askIfExistingEntryShouldBeAdded($helperSet, $input, $output, $entryNumber);
6774
};
6875

69-
foreach ((array) $form->getData() as $key => $entryData) {
76+
foreach ($data as $key => $entryData) {
7077
$this->printEditEntryHeader($key, $output);
7178
$prototype->setData($entryData);
7279

0 commit comments

Comments
 (0)