Skip to content

Commit

Permalink
Mark form as nullable
Browse files Browse the repository at this point in the history
  • Loading branch information
jankonas authored and f3l1x committed Mar 9, 2021
1 parent 45ed76a commit d785434
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class Multiplier extends Container

public const SUBMIT_REMOVE_NAME = 'multiplier_remover';

/** @var Form */
/** @var Form|null */
private $form;

/** @var bool */
Expand Down Expand Up @@ -279,7 +279,7 @@ private function createComponents(ComponentResolver $resolver): void
}

// New containers, if create button hitted
if ($resolver->isCreateAction() && $this->form->isValid()) {
if ($this->form !== null && $resolver->isCreateAction() && $this->form->isValid()) {
$count = $resolver->getCreateNum();
while ($count > 0 && $this->isValidMaxCopies()) {
$this->noValidate[] = $containers[] = $container = $this->addCopy();
Expand Down Expand Up @@ -313,7 +313,7 @@ public function createCopies(): void
$this->attachCreateButtons();
}

if ($resolver->isRemoveAction() && $this->totalCopies >= $this->minCopies && !$resolver->reachedMinLimit()) {
if ($this->form !== null && $resolver->isRemoveAction() && $this->totalCopies >= $this->minCopies && !$resolver->reachedMinLimit()) {
/** @var RemoveButton $removeButton */
$removeButton = $this->removeButton;
$this->form->setSubmittedBy($removeButton->create($this));
Expand Down Expand Up @@ -367,7 +367,7 @@ protected function isFormSubmitted(): bool

protected function loadHttpData(): void
{
if ($this->isFormSubmitted()) {
if ($this->form !== null && $this->isFormSubmitted()) {
$this->httpData = Arrays::get($this->form->getHttpData(), $this->getHtmlName(), []);
}
}
Expand Down Expand Up @@ -454,6 +454,10 @@ protected function removeComponentProperly(IComponent $component): void
*/
public function resetFormEvents(): void
{
if ($this->form === null) {
return;
}

$this->form->onSuccess = $this->form->onError = $this->form->onSubmit = [];
}

Expand Down

0 comments on commit d785434

Please sign in to comment.