mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Allow int casts if the type comes from calculation (#4768)
This commit is contained in:
parent
c60eada3f7
commit
48f55f3c3b
@ -48,20 +48,22 @@ class CastAnalyzer
|
||||
|
||||
if ($maybe_type) {
|
||||
if ($maybe_type->isInt()) {
|
||||
if ($maybe_type->from_docblock) {
|
||||
$issue = new RedundantCastGivenDocblockType(
|
||||
'Redundant cast to ' . $maybe_type->getKey() . ' given docblock-provided type',
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
);
|
||||
} else {
|
||||
$issue = new RedundantCast(
|
||||
'Redundant cast to ' . $maybe_type->getKey(),
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
);
|
||||
}
|
||||
if (!$maybe_type->from_calculation) {
|
||||
if ($maybe_type->from_docblock) {
|
||||
$issue = new RedundantCastGivenDocblockType(
|
||||
'Redundant cast to ' . $maybe_type->getKey() . ' given docblock-provided type',
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
);
|
||||
} else {
|
||||
$issue = new RedundantCast(
|
||||
'Redundant cast to ' . $maybe_type->getKey(),
|
||||
new CodeLocation($statements_analyzer->getSource(), $stmt)
|
||||
);
|
||||
}
|
||||
|
||||
if (IssueBuffer::accepts($issue, $statements_analyzer->getSuppressedIssues())) {
|
||||
// fall through
|
||||
if (IssueBuffer::accepts($issue, $statements_analyzer->getSuppressedIssues())) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -791,6 +791,12 @@ class RedundantConditionTest extends \Psalm\Tests\TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'noRedundantCastAfterCalculation' => [
|
||||
'<?php
|
||||
function x(string $x): int {
|
||||
return (int) (hexdec($x) + 1);
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user