Skip to content

Commit b2dae42

Browse files
committed
wip
1 parent 0ab5b8d commit b2dae42

File tree

2 files changed

+30
-22
lines changed

2 files changed

+30
-22
lines changed

src/Analyser/MutatingScope.php

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
use function is_string;
151151
use function ltrim;
152152
use function md5;
153+
use function preg_match;
153154
use function sprintf;
154155
use function str_starts_with;
155156
use function strlen;
@@ -2224,25 +2225,45 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
22242225
}
22252226

22262227
if ($node instanceof FuncCall) {
2227-
if ($node->name instanceof Expr) {
2228+
$functionName = null;
2229+
if ($node->name instanceof Name) {
2230+
$functionName = $node->name;
2231+
} elseif ($node->name instanceof Expr) {
22282232
$calledOnType = $this->getType($node->name);
22292233
if ($calledOnType->isCallable()->no()) {
22302234
return new ErrorType();
22312235
}
22322236

2233-
return ParametersAcceptorSelector::selectFromArgs(
2234-
$this,
2235-
$node->getArgs(),
2236-
$calledOnType->getCallableParametersAcceptors($this),
2237-
null,
2238-
)->getReturnType();
2237+
if ($node->name instanceof String_) {
2238+
/** @var non-empty-string $name */
2239+
$name = $node->name->value;
2240+
$functionName = new Name($name);
2241+
} elseif ($node->name instanceof FuncCall && $node->name->isFirstClassCallable() &&
2242+
$node->name->getAttribute('phpstan_cache_printer') !== null &&
2243+
preg_match('/\A(?<name>\\\\?[^()]+)\(...\)\z/', $node->name->getAttribute('phpstan_cache_printer'), $m) === 1
2244+
) {
2245+
/** @var non-falsy-string $name */
2246+
$name = $m['name'];
2247+
$functionName = new Name($name);
2248+
} else {
2249+
return ParametersAcceptorSelector::selectFromArgs(
2250+
$this,
2251+
$node->getArgs(),
2252+
$calledOnType->getCallableParametersAcceptors($this),
2253+
null,
2254+
)->getReturnType();
2255+
}
2256+
}
2257+
2258+
if ($functionName === null) {
2259+
throw new ShouldNotHappenException();
22392260
}
22402261

2241-
if (!$this->reflectionProvider->hasFunction($node->name, $this)) {
2262+
if (!$this->reflectionProvider->hasFunction($functionName, $this)) {
22422263
return new ErrorType();
22432264
}
22442265

2245-
$functionReflection = $this->reflectionProvider->getFunction($node->name, $this);
2266+
$functionReflection = $this->reflectionProvider->getFunction($functionName, $this);
22462267
if ($this->nativeTypesPromoted) {
22472268
return ParametersAcceptorSelector::combineAcceptors($functionReflection->getVariants())->getNativeReturnType();
22482269
}

src/Type/Php/ArrayMapFunctionReturnTypeExtension.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use PHPStan\Type\TypeUtils;
2424
use function array_slice;
2525
use function count;
26-
use function preg_match;
2726

2827
final class ArrayMapFunctionReturnTypeExtension implements DynamicFunctionReturnTypeExtension
2928
{
@@ -51,18 +50,6 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
5150
}
5251
$valueType = TypeCombinator::union(...$valueTypes);
5352
$callback = $functionCall->getArgs()[0]->value;
54-
if ($callback instanceof String_) {
55-
/** @var non-falsy-string $callName */
56-
$callName = $callback->value;
57-
$callback = new Name($callName);
58-
} elseif ($callback instanceof FuncCall && $callback->isFirstClassCallable() &&
59-
$callback->getAttribute('phpstan_cache_printer') !== null &&
60-
preg_match('/\A(?<name>\\\\?[^()]+)\(...\)\z/', $callback->getAttribute('phpstan_cache_printer'), $m) === 1
61-
) {
62-
/** @var non-falsy-string $callName */
63-
$callName = $m['name'];
64-
$callback = new Name($callName);
65-
}
6653
} elseif ($callableIsNull) {
6754
$arrayBuilder = ConstantArrayTypeBuilder::createEmpty();
6855
foreach (array_slice($functionCall->getArgs(), 1) as $index => $arg) {

0 commit comments

Comments
 (0)