|
150 | 150 | use function is_string;
|
151 | 151 | use function ltrim;
|
152 | 152 | use function md5;
|
| 153 | +use function preg_match; |
153 | 154 | use function sprintf;
|
154 | 155 | use function str_starts_with;
|
155 | 156 | use function strlen;
|
@@ -2224,25 +2225,45 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
|
2224 | 2225 | }
|
2225 | 2226 |
|
2226 | 2227 | 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) { |
2228 | 2232 | $calledOnType = $this->getType($node->name);
|
2229 | 2233 | if ($calledOnType->isCallable()->no()) {
|
2230 | 2234 | return new ErrorType();
|
2231 | 2235 | }
|
2232 | 2236 |
|
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(); |
2239 | 2260 | }
|
2240 | 2261 |
|
2241 |
| - if (!$this->reflectionProvider->hasFunction($node->name, $this)) { |
| 2262 | + if (!$this->reflectionProvider->hasFunction($functionName, $this)) { |
2242 | 2263 | return new ErrorType();
|
2243 | 2264 | }
|
2244 | 2265 |
|
2245 |
| - $functionReflection = $this->reflectionProvider->getFunction($node->name, $this); |
| 2266 | + $functionReflection = $this->reflectionProvider->getFunction($functionName, $this); |
2246 | 2267 | if ($this->nativeTypesPromoted) {
|
2247 | 2268 | return ParametersAcceptorSelector::combineAcceptors($functionReflection->getVariants())->getNativeReturnType();
|
2248 | 2269 | }
|
|
0 commit comments