Skip to content

Commit 7fcc69a

Browse files
phpstan-botclaude
andcommitted
Drop strval()/intval() forms from decimal-int-string round-trip detection
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 5c62c33 commit 7fcc69a

2 files changed

Lines changed: 3 additions & 35 deletions

File tree

‎src/Analyser/TypeSpecifier.php‎

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2971,7 +2971,7 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
29712971
/**
29722972
* When $castExpr casts $valueExpr to an int and back to a string — i.e. the
29732973
* `(string) (int) $valueExpr` round-trip (in any combination of the (string)/(int)
2974-
* casts and the strval()/intval() function forms) — returns $valueExpr so the
2974+
* casts) — returns $valueExpr so the
29752975
* comparison `$castExpr === $valueExpr` can narrow it to a decimal / non-decimal
29762976
* integer string. This is the canonical "decimal integer string" round-trip that
29772977
* ConstantStringType::isDecimalIntegerString() checks with `(string) (int) $value === $value`.
@@ -3008,24 +3008,14 @@ private function getDecimalIntegerStringRoundTripExpr(Expr $castExpr, Expr $valu
30083008
}
30093009

30103010
/**
3011-
* Strips a single (string)/(int) cast or strval()/intval() call, returning its inner expression.
3011+
* Strips a single (string)/(int) cast, returning its inner expression.
30123012
*/
30133013
private function getCastInnerExpr(Expr $expr): ?Expr
30143014
{
30153015
if ($expr instanceof Expr\Cast\String_ || $expr instanceof Expr\Cast\Int_) {
30163016
return $expr->expr;
30173017
}
30183018

3019-
if (
3020-
$expr instanceof FuncCall
3021-
&& $expr->name instanceof Name
3022-
&& !$expr->isFirstClassCallable()
3023-
&& in_array(strtolower($expr->name->toString()), ['strval', 'intval'], true)
3024-
&& count($expr->getArgs()) === 1
3025-
) {
3026-
return $expr->getArgs()[0]->value;
3027-
}
3028-
30293019
return null;
30303020
}
30313021

@@ -3291,7 +3281,7 @@ private function resolveNormalizedIdentical(Expr\BinaryOp\Identical $expr, Scope
32913281
}
32923282
}
32933283

3294-
// (string) (int) $x === $x (and the strval(intval()) equivalents)
3284+
// (string) (int) $x === $x
32953285
if (!$context->null()) {
32963286
$decimalValueExpr = $this->getDecimalIntegerStringRoundTripExpr($unwrappedLeftExpr, $unwrappedRightExpr, $scope)
32973287
?? $this->getDecimalIntegerStringRoundTripExpr($unwrappedRightExpr, $unwrappedLeftExpr, $scope);

‎tests/PHPStan/Analyser/nsrt/decimal-int-string-cast.php‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
namespace DecimalIntStringCast;
44

55
use function PHPStan\Testing\assertType;
6-
use function intval;
7-
use function strval;
86

97
class Foo
108
{
@@ -36,26 +34,6 @@ public function castNotIdentical(string $s): void
3634
}
3735
}
3836

39-
public function strvalIntval(string $s): void
40-
{
41-
if (strval(intval($s)) === $s) {
42-
assertType('decimal-int-string', $s);
43-
} else {
44-
assertType('non-decimal-int-string', $s);
45-
}
46-
}
47-
48-
public function mixedCastForms(string $s): void
49-
{
50-
if (strval((int) $s) === $s) {
51-
assertType('decimal-int-string', $s);
52-
}
53-
54-
if ((string) intval($s) === $s) {
55-
assertType('decimal-int-string', $s);
56-
}
57-
}
58-
5937
public function notAlwaysString(int|string $s): void
6038
{
6139
if ((string) (int) $s === $s) {

0 commit comments

Comments
 (0)