From dcd32fee4c952d338947b530292dcaa25dffedc9 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Wed, 10 Sep 2025 12:22:28 +0200 Subject: [PATCH] Allow to cast resource to float --- src/Type/ResourceType.php | 2 +- tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php | 6 +++--- tests/PHPStan/Rules/Cast/data/invalid-cast.php | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Type/ResourceType.php b/src/Type/ResourceType.php index 3e83e3d819..01e7fe86e0 100644 --- a/src/Type/ResourceType.php +++ b/src/Type/ResourceType.php @@ -72,7 +72,7 @@ public function toInteger(): Type public function toFloat(): Type { - return new ErrorType(); + return new FloatType(); } public function toArray(): Type diff --git a/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php b/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php index cad88fb000..3bbc8521a5 100644 --- a/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php +++ b/tests/PHPStan/Rules/Cast/InvalidCastRuleTest.php @@ -43,15 +43,15 @@ public function testRule(): void ], [ 'Cannot cast object to string.', - 35, + 36, ], [ 'Cannot cast Test\\Foo to string.', - 41, + 42, ], [ 'Cannot cast array|float|int to string.', - 48, + 49, ], ]); } diff --git a/tests/PHPStan/Rules/Cast/data/invalid-cast.php b/tests/PHPStan/Rules/Cast/data/invalid-cast.php index 4c48e6acfa..061f41342f 100644 --- a/tests/PHPStan/Rules/Cast/data/invalid-cast.php +++ b/tests/PHPStan/Rules/Cast/data/invalid-cast.php @@ -25,6 +25,7 @@ function ( (string) fopen('php://memory', 'r'); (int) fopen('php://memory', 'r'); + (float) fopen('php://memory', 'r'); }; function (