Skip to content

Commit

Permalink
Multiplier::validate(): Filter out non-validatable components
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jtojnar committed Apr 17, 2024
1 parent 2afcd08 commit 319362e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ public function addCreateButton(?string $caption = null, int $copyCount = 1): Cr
*/
public function validate(?array $controls = null): void
{
/** @var Control[] $components */
$components = $controls ?? $this->getComponents();
$components = $controls ?? array_filter($this->getComponents(), fn ($component) => $component instanceof Control || $component instanceof Container);

foreach ($components as $index => $control) {
foreach ($this->noValidate as $item) {
Expand Down

0 comments on commit 319362e

Please sign in to comment.