Skip to content

Commit

Permalink
fix: call getMethod on template type directly (#1913)
Browse files Browse the repository at this point in the history
  • Loading branch information
canvural committed Apr 14, 2024
1 parent 3e28082 commit 744923c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Methods/HigherOrderTapProxyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\MethodsClassReflectionExtension;
use PHPStan\ShouldNotHappenException;

final class HigherOrderTapProxyExtension implements MethodsClassReflectionExtension
{
Expand All @@ -35,8 +36,10 @@ public function getMethod(
): MethodReflection {
$templateType = $classReflection->getActiveTemplateTypeMap()->getType('TClass');

$reflection = $templateType->getObjectClassReflections()[0]; // @phpstan-ignore-line
if ($templateType === null || $templateType->getObjectClassReflections() === [] || ! $templateType->hasMethod($methodName)->yes()) {
throw new ShouldNotHappenException();
}

return $reflection->getMethod($methodName, new OutOfClassScope());
return $templateType->getMethod($methodName, new OutOfClassScope());
}
}
1 change: 1 addition & 0 deletions tests/Type/data/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ function tapHelper()

assertType('Illuminate\Support\HigherOrderTapProxy<App\User>', tap(new User()));
assertType('App\User', tap(new User())->update(['name' => 'Taylor Otwell']));
assertType('Illuminate\Contracts\Validation\Validator&Illuminate\Validation\Validator', tap(validator([], []))->addReplacers());
}

function urlHelper()
Expand Down

0 comments on commit 744923c

Please sign in to comment.