-
Notifications
You must be signed in to change notification settings - Fork 4
Closed
Description
Hi, and thanks for this phpstan addon. I use it in a legay php project and step-by-step the magic numbers will be replaced with constants that I can understand. 👍
The situation: I updated the php application from 7.4 to 8.3 and now I use vesion 0.4.3
but I see many new errors from numerc-strings. For now I will use sidzIgnoreNumericStrings: true
but I think ignoring should be work also for numeric-strings.
The problem: ignoreNumber()
will check the type of the config value but numeric-strings are not allowed here, I see messages like this: The item 'parameters › sidzIgnoreMagicNumbers › 2' expects to be number, '0' given.
if I try to add '2'
or "2"
in for sidzIgnoreMagicNumbers
.
Code:
/**
* @param LNumber|DNumber $scalar
*/
private function ignoreNumber(Expr $scalar): bool
{
return in_array($scalar->value, $this->ignoreMagicNumbers, true);
}
Possible fix: ?
/**
* @param LNumber|DNumber $scalar
*/
private function ignoreNumber(Expr $scalar): bool
{
$ignoreMagicNumbersStrings = array_map(function($obj) {
return (string) $obj;
}, $this->ignoreMagicNumbers);
return in_array($scalar->value, $this->ignoreMagicNumbers, true) || in_array($scalar->value, $ignoreMagicNumbersStrings, true);
}
sidz
Metadata
Metadata
Assignees
Labels
No labels