Skip to content

Commit 0566665

Browse files
authored
Fix an issue when sidzIgnoreNumericStrings is disabled but extension doesn't report numeric strings. Convert all values to strings (#24)
1 parent aaba306 commit 0566665

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/Rules/MagicNumber/AbstractMagicNumberRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function isNumeric(?Expr $expr): bool
3939
*/
4040
private function ignoreNumber(Expr $scalar): bool
4141
{
42-
return in_array($scalar->value, $this->ignoreMagicNumbers, true);
42+
return in_array((string) $scalar->value, array_map('strval', $this->ignoreMagicNumbers), true);
4343
}
4444

4545
private function isNumericString(?Expr $expr): bool

tests/Rules/MagicNumber/data/assignment-case.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function test_func($var4 = 3): void
99
$var5 = 0;
1010
$var5_1 = 1;
1111
$var5_2 = 2;
12-
$var = '0';
12+
$var = '3';
1313
}
1414

1515
$var6 = .1;
@@ -37,3 +37,5 @@ public function calc(): int
3737
$var = '-5';
3838

3939
$var = new stdClass();
40+
41+
$var = '0';

tests/Rules/MagicNumber/data/match-case.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
1 => 'Hi',
77
2, 4 => 'There',
88
'string in the middle', '5' => 'There',
9-
'1', 6 => 'magic number after string',
9+
'2', 6 => 'magic number after string',
1010
default => throw new LogicException(),
1111
0 => 'Hello',
1212
};

0 commit comments

Comments
 (0)