diff --git a/composer.json b/composer.json index 195c11c..78da0ae 100644 --- a/composer.json +++ b/composer.json @@ -7,7 +7,7 @@ ], "require": { "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^1.4.7" + "phpstan/phpstan": "^1.4.8" }, "require-dev": { "nikic/php-parser": "^4.13.0", diff --git a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php index 1090363..6480d97 100644 --- a/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php +++ b/src/Type/WebMozartAssert/AssertTypeSpecifyingExtension.php @@ -12,6 +12,7 @@ use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BinaryOp\BooleanAnd; use PhpParser\Node\Expr\BinaryOp\BooleanOr; +use PhpParser\Node\Expr\BinaryOp\Equal; use PhpParser\Node\Expr\BinaryOp\Greater; use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual; use PhpParser\Node\Expr\BinaryOp\Identical; @@ -19,6 +20,7 @@ use PhpParser\Node\Expr\BinaryOp\Smaller; use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual; use PhpParser\Node\Expr\BooleanNot; +use PhpParser\Node\Expr\Cast\Int_; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Instanceof_; @@ -236,9 +238,17 @@ private static function getExpressionResolvers(): array ); }, 'integerish' => static function (Scope $scope, Arg $value): Expr { - return new FuncCall( - new Name('is_numeric'), - [$value] + return new BooleanAnd( + new FuncCall( + new Name('is_numeric'), + [$value] + ), + new Equal( + $value->value, + new Int_( + $value->value + ) + ) ); }, 'numeric' => static function (Scope $scope, Arg $value): Expr { diff --git a/tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php b/tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php index bca1e3c..9ece46c 100644 --- a/tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php +++ b/tests/Type/WebMozartAssert/ImpossibleCheckTypeMethodCallRuleTest.php @@ -65,6 +65,11 @@ public function testBug8(): void ]); } + public function testBug32(): void + { + $this->analyse([__DIR__ . '/data/bug-32.php'], []); + } + public function testBug33(): void { $this->analyse([__DIR__ . '/data/bug-33.php'], []); diff --git a/tests/Type/WebMozartAssert/data/bug-32.php b/tests/Type/WebMozartAssert/data/bug-32.php new file mode 100644 index 0000000..56acfdc --- /dev/null +++ b/tests/Type/WebMozartAssert/data/bug-32.php @@ -0,0 +1,17 @@ +