Skip to content
Permalink
Browse files

Fix #1801 - add support for class_exists(Foo::class) too

  • Loading branch information...
muglug committed Jun 17, 2019
1 parent 4c57c67 commit 250ef02687dd12088329a292852cb9c5259c921e
@@ -624,8 +624,17 @@ function (Assertion $assertion) use ($generic_params) : Assertion {
if ($function->parts === ['method_exists']) {
$context->check_methods = false;
} elseif ($function->parts === ['class_exists']) {
if ($first_arg && $first_arg->value instanceof PhpParser\Node\Scalar\String_) {
$context->phantom_classes[strtolower($first_arg->value->value)] = true;
if ($first_arg) {
if ($first_arg->value instanceof PhpParser\Node\Scalar\String_) {
$context->phantom_classes[strtolower($first_arg->value->value)] = true;
} elseif ($first_arg->value instanceof PhpParser\Node\Expr\ClassConstFetch
&& $first_arg->value->class instanceof PhpParser\Node\Name
&& $first_arg->value->name instanceof PhpParser\Node\Identifier
&& $first_arg->value->name->name === 'class'
) {
$resolved_name = (string) $first_arg->value->class->getAttribute('resolvedName');
$context->phantom_classes[strtolower($resolved_name)] = true;
}
}
} elseif ($function->parts === ['file_exists'] && $first_arg) {
$var_id = ExpressionAnalyzer::getArrayVarId($first_arg->value, null);
@@ -569,6 +569,28 @@ function foo() : void {
if (!is_subclass_of($s, A::class)) {}
}',
],
'allowClassExistsCheckOnClassString' => [
'<?php
class C
{
public function __construct() {
if (class_exists(\Doesnt\Really::class)) {
\Doesnt\Really::something();
}
}
}'
],
'allowClassExistsCheckOnString' => [
'<?php
class C
{
public function __construct() {
if (class_exists("Doesnt\\Really")) {
\Doesnt\Really::something();
}
}
}'
],
];
}

0 comments on commit 250ef02

Please sign in to comment.
You can’t perform that action at this time.