Skip to content

Commit d089af9

Browse files
author
Emil Masiakowski
committed
Support classExists and interfaceExists
1 parent b4df461 commit d089af9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Type/BeberleiAssert/AssertHelper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,14 @@ private static function getExpressionResolvers(): array
401401
new Name('method_exists'),
402402
[$object, $property],
403403
),
404+
'classExists' => static fn (Scope $scope, Arg $value): Expr => new FuncCall(
405+
new Name('class_exists'),
406+
[$value],
407+
),
408+
'interfaceExists' => static fn (Scope $scope, Arg $value): Expr => new FuncCall(
409+
new Name('interface_exists'),
410+
[$value],
411+
),
404412
'notBlank' => static fn (Scope $scope, Arg $value): Expr => new BooleanAnd(
405413
new BooleanAnd(
406414
new NotIdentical(

tests/Type/BeberleiAssert/data/data.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ public function doFoo($a, $b, array $c, iterable $d, $e, $f, $g, $h, $i, $j, $k,
4747
Assertion::methodExists($j, 'doBar');
4848
\PHPStan\Testing\assertType('object&hasMethod(doBar)&hasProperty(foo)', $j);
4949

50+
/** @var string $classString */
51+
$classString = doFoo();
52+
Assertion::classExists($classString);
53+
\PHPStan\Testing\assertType('class-string', $classString);
54+
55+
/** @var string $interfaceString */
56+
$interfaceString = doFoo();
57+
Assertion::interfaceExists($interfaceString);
58+
\PHPStan\Testing\assertType('class-string', $interfaceString);
59+
5060
Assertion::isResource($k);
5161
\PHPStan\Testing\assertType('resource', $k);
5262

0 commit comments

Comments
 (0)