Add missing type to solve PHPStan errors#6979
Conversation
| 'nullable_type_declaration_for_default_null_value' => true, | ||
| 'phpdoc_to_comment' => false, | ||
| // Override @Symfony ruleset to keep mixed return type for PHPStan | ||
| 'no_superfluous_phpdoc_tags' => ['allow_hidden_params' => true, 'allow_mixed' => true, 'remove_inheritdoc' => true], |
There was a problem hiding this comment.
Without this, php-cs-fixer removes
@param mixed $foo
or
@return mixed
Which is needed for phpstan.
| private array $numberFormatters = []; | ||
|
|
||
| public function formatCurrency($amount, string $currency, array $attrs = [], ?string $locale = null): string | ||
| public function formatCurrency(int|float $amount, string $currency, array $attrs = [], ?string $locale = null): string |
There was a problem hiding this comment.
- Class is final
- The interface ask for int|float
$formatter->formatCurrencyneedint|float
So it's ok to type amount.
| } | ||
|
|
||
| /** | ||
| * @param \DateTimeZone|string|bool|null $timezone $timezone |
There was a problem hiding this comment.
Param is coming from formatDateTime which only use phpdoc so I have to do the same
| * @param mixed[] &$array | ||
| */ | ||
| private function recursiveKsort(&$array): void | ||
| private function recursiveKsort(array &$array): void |
There was a problem hiding this comment.
It's always called with an array
| private ?iterable $results = null; | ||
| private ?int $numResults = null; |
There was a problem hiding this comment.
We have
public function getNumResults(): int
{
return $this->numResults;
}
public function getResults(): ?iterable
{
return $this->results;
}
So I'm not sure with which value I have to initialize the $numResult (there will a be a ?int vs int level 8) but I copied the existing behavior (without type).
| } | ||
|
|
||
| public function updateProperty(EntityDto $entityDto, string $propertyName, $value): void | ||
| public function updateProperty(EntityDto $entityDto, string $propertyName, mixed $value): void |
There was a problem hiding this comment.
As far I known, adding mixed as param type is BC even if the class is not final.
| } | ||
|
|
||
| public function isGranted($permission, $subject = null, ?AccessDecision $accessDecision = null): bool | ||
| public function isGranted(mixed $attribute, mixed $subject = null, ?AccessDecision $accessDecision = null): bool |
There was a problem hiding this comment.
$attribute is the param name of the parent.
src/Twig/EasyAdminTwigExtension.php
Outdated
| * Transforms ['a' => 'foo', 'b' => ['c' => ['d' => 7]]] into ['a' => 'foo', 'b[c][d]' => 7] | ||
| * It's useful to submit nested arrays (e.g. query string parameters) as form fields. | ||
| * | ||
| * @param mixed[] $array |
There was a problem hiding this comment.
To stay BC, I only added phpdoc
javiereguiluz
left a comment
There was a problem hiding this comment.
Thanks a lot Vincent.
I like this a lot and, after reviewing it, I think it's correct (including the new mixed types). I'll wait a bit more before merging this in case someone else wants to review it.
Thanks!
|
Merged! Thanks. |
This solve ~30 PHPStan error of level 6 which represent 10% of missing types.
I started with a small PR to validate it's the way you want to solve them (and you agree it's BC).