Skip to content

Commit ae7f2ad

Browse files
committed
Remember function_exists() from constructor
1 parent 39c396e commit ae7f2ad

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Diff for: src/Analyser/MutatingScope.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ private function rememberConstructorExpressions(array $currentExpressionTypes):
306306
if ($expr instanceof FuncCall) {
307307
if (
308308
!$expr->name instanceof Name
309-
|| !in_array($expr->name->name, ['class_exists'], true)
309+
|| !in_array($expr->name->name, ['class_exists', 'function_exists'], true)
310310
) {
311311
continue;
312312
}

Diff for: tests/PHPStan/Rules/Functions/CallToNonExistentFunctionRuleTest.php

+5
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,9 @@ public function testBug10003(): void
258258
]);
259259
}
260260

261+
public function testRememberFunctionExistsFromConstructor(): void
262+
{
263+
$this->analyse([__DIR__ . '/data/remember-function-exists-from-constructor.php'], []);
264+
}
265+
261266
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php // lint >= 7.4
2+
3+
namespace RememberFunctionExistsFromConstructor;
4+
5+
class User
6+
{
7+
public function __construct(
8+
) {
9+
if (!function_exists('some_unknown_function')) {
10+
throw new \LogicException();
11+
}
12+
}
13+
14+
public function doFoo(): void
15+
{
16+
some_unknown_function();
17+
}
18+
19+
}

0 commit comments

Comments
 (0)