diff --git a/src/Type/BeberleiAssert/AssertHelper.php b/src/Type/BeberleiAssert/AssertHelper.php index f3f73a3..49e34e2 100644 --- a/src/Type/BeberleiAssert/AssertHelper.php +++ b/src/Type/BeberleiAssert/AssertHelper.php @@ -393,6 +393,22 @@ private static function getExpressionResolvers(): array [$key, $array], ), ), + 'propertyExists' => static fn (Scope $scope, Arg $object, Arg $property): Expr => new FuncCall( + new Name('property_exists'), + [$object, $property], + ), + 'methodExists' => static fn (Scope $scope, Arg $object, Arg $method): Expr => new FuncCall( + new Name('method_exists'), + [$object, $method], + ), + 'classExists' => static fn (Scope $scope, Arg $value): Expr => new FuncCall( + new Name('class_exists'), + [$value], + ), + 'interfaceExists' => static fn (Scope $scope, Arg $value): Expr => new FuncCall( + new Name('interface_exists'), + [$value], + ), 'notBlank' => static fn (Scope $scope, Arg $value): Expr => new BooleanAnd( new BooleanAnd( new NotIdentical( diff --git a/tests/Type/BeberleiAssert/data/data.php b/tests/Type/BeberleiAssert/data/data.php index 57cf656..a38ae8a 100644 --- a/tests/Type/BeberleiAssert/data/data.php +++ b/tests/Type/BeberleiAssert/data/data.php @@ -41,6 +41,22 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k, Assertion::objectOrClass($j); \PHPStan\Testing\assertType('object', $j); + Assertion::propertyExists($j, 'foo'); + \PHPStan\Testing\assertType('object&hasProperty(foo)', $j); + + Assertion::methodExists($j, 'doBar'); + \PHPStan\Testing\assertType('object&hasMethod(doBar)&hasProperty(foo)', $j); + + /** @var string $classString */ + $classString = doFoo(); + Assertion::classExists($classString); + \PHPStan\Testing\assertType('class-string', $classString); + + /** @var string $interfaceString */ + $interfaceString = doFoo(); + Assertion::interfaceExists($interfaceString); + \PHPStan\Testing\assertType('class-string', $interfaceString); + Assertion::isResource($k); \PHPStan\Testing\assertType('resource', $k);