Skip to content

Commit

Permalink
Multiplier: Add missing param typehint to getValues
Browse files Browse the repository at this point in the history
This fixes the following PHPStan errors:

  280    Method Contributte\FormMultiplier\Multiplier::getValues() has parameter $returnType with no type specified.
  290    No error to ignore is reported on line 290.

Let’s also deprecate passing bool `$returnType` deprecated like `nette/forms` 3.2.0 does:

nette/forms@0a812bd

Also use Array constant made public in 3.1.12:

nette/forms@0be7b3d
  • Loading branch information
jtojnar committed Feb 17, 2024
1 parent 9b4e600 commit 6a4c71c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
],
"require": {
"php": ">=8.0",
"nette/forms": "^3.1.0"
"nette/forms": "^3.1.12"
},
"require-dev": {
"codeception/codeception": "^4.1.9",
Expand Down
13 changes: 8 additions & 5 deletions src/Multiplier.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,9 @@ public function resetFormEvents(): void
}

/**
* @param string|object|bool|null $returnType 'array' for array
* @param Control[]|null $controls
* @return object|mixed[]
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingAnyTypeHint
*/
public function getValues($returnType = null, ?array $controls = null): object|array

Check failure on line 284 in src/Multiplier.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.1)

Method \Contributte\FormMultiplier\Multiplier::getValues() does not have native type hint for its parameter $returnType but it should be possible to add it based on @param annotation "string|object|bool|null".
{
Expand All @@ -288,12 +288,15 @@ public function getValues($returnType = null, ?array $controls = null): object|a
}

/** @var mixed[] $values */
$values = parent::getValues('array', $controls);
$values = parent::getValues(self::Array, $controls);
$values = array_values($values);

$returnType = $returnType === true ? 'array' : $returnType; // @phpstan-ignore-line nette backwards compatibility
if ($returnType === true) {
trigger_error(static::class . '::' . __FUNCTION__ . "(true) is deprecated, use getValues('array').", E_USER_DEPRECATED);
$returnType = self::Array;
}

return $returnType === 'array' ? $values : ArrayHash::from($values);
return $returnType === self::Array ? $values : ArrayHash::from($values);
}

/**
Expand Down Expand Up @@ -453,7 +456,7 @@ protected function removeComponentProperly(IComponent $component): void
private function createComponents(bool $forceValues = false): void
{
$containers = [];
$containerDefaults = $this->createContainer()->getValues('array');
$containerDefaults = $this->createContainer()->getValues(self::Array);

// Components from httpData
if ($this->isFormSubmitted() && !$forceValues) {
Expand Down

0 comments on commit 6a4c71c

Please sign in to comment.