Skip to content

Commit

Permalink
Make function_exists() similar to is_callable()
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Nov 6, 2021
1 parent 28e8c11 commit 4a98863
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
Expand Up @@ -12,6 +12,7 @@
use PHPStan\Analyser\TypeSpecifierAwareExtension;
use PHPStan\Analyser\TypeSpecifierContext;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Type\CallableType;
use PHPStan\Type\Constant\ConstantBooleanType;
use PHPStan\Type\Constant\ConstantStringType;
use PHPStan\Type\FunctionTypeSpecifyingExtension;
Expand Down Expand Up @@ -45,7 +46,13 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
);
}

return new SpecifiedTypes();
return $this->typeSpecifier->create(
$node->getArgs()[0]->value,
new CallableType(),
$context,
false,
$scope
);
}

public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void
Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/CallCallablesRuleTest.php
Expand Up @@ -213,4 +213,9 @@ public function testRuleWithNullsafeVariant(): void
]);
}

public function testBug1849(): void
{
$this->analyse([__DIR__ . '/data/bug-1849.php'], []);
}

}
11 changes: 11 additions & 0 deletions tests/PHPStan/Rules/Functions/data/bug-1849.php
@@ -0,0 +1,11 @@
<?php

namespace Bug1849;

function (string $type): void {
$func = 'is_' . $type;

if (function_exists($func)) {
$func([]);
}
};

0 comments on commit 4a98863

Please sign in to comment.