Skip to content

Commit 7a702b1

Browse files
committed
Multiplier::validate(): Filter out non-validatable components
45ed76a started filtering components to `Control`s, to appease PHPStan, since `Container::validate()` only accepted `Control[]`. But `Multiplier` does not actually have `Control`s as direct children (other than the ‘Add’ `Submitter`s), so it would stop validating and filtering multiplied controls. a5a7348 reverted that part but kept the incorrect phpdoc type cast. Now, it works without the filter because `Container::validate()` already ignores non-validatable components but we should still respect its contract. Let’s filter the components before passing them down. This will also allow us to drop the lying phpdoc type cast. nette/forms 3.2.2 updated its phpdoc param type to allow that: nette/forms@6437671
1 parent 71cc347 commit 7a702b1

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

src/Multiplier.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,7 @@ public function addCreateButton(?string $caption = null, int $copyCount = 1): Cr
170170
*/
171171
public function validate(?array $controls = null): void
172172
{
173-
/** @var Control[] $components */
174-
$components = $controls ?? $this->getComponents();
173+
$components = $controls ?? array_filter($this->getComponents(), fn ($component) => $component instanceof Control || $component instanceof Container);
175174

176175
foreach ($components as $index => $control) {
177176
foreach ($this->noValidate as $item) {

0 commit comments

Comments
 (0)