Skip to content

Commit ef44053

Browse files
authored
Add @template typehints for make / instance / app to improve type hints (#41557)
- This enables resolving type of instance that container resolves without any IDE plugins. - Helps phpstan / psalm / other tools
1 parent a25eb78 commit ef44053

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed

src/Illuminate/Container/Container.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,10 @@ public function extend($abstract, Closure $closure)
461461
/**
462462
* Register an existing instance as shared in the container.
463463
*
464+
* @template T
464465
* @param string $abstract
465-
* @param mixed $instance
466-
* @return mixed
466+
* @param T $instance
467+
* @return T
467468
*/
468469
public function instance($abstract, $instance)
469470
{
@@ -683,9 +684,10 @@ public function makeWith($abstract, array $parameters = [])
683684
/**
684685
* Resolve the given type from the container.
685686
*
686-
* @param string|callable $abstract
687+
* @template T
688+
* @param class-string<T> $abstract
687689
* @param array $parameters
688-
* @return mixed
690+
* @return T|mixed
689691
*
690692
* @throws \Illuminate\Contracts\Container\BindingResolutionException
691693
*/

src/Illuminate/Contracts/Container/Container.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,10 @@ public function extend($abstract, Closure $closure);
113113
/**
114114
* Register an existing instance as shared in the container.
115115
*
116+
* @template T
116117
* @param string $abstract
117-
* @param mixed $instance
118-
* @return mixed
118+
* @param T $instance
119+
* @return T
119120
*/
120121
public function instance($abstract, $instance);
121122

@@ -155,9 +156,10 @@ public function flush();
155156
/**
156157
* Resolve the given type from the container.
157158
*
158-
* @param string $abstract
159+
* @template T
160+
* @param class-string<T> $abstract
159161
* @param array $parameters
160-
* @return mixed
162+
* @return T|mixed
161163
*
162164
* @throws \Illuminate\Contracts\Container\BindingResolutionException
163165
*/

src/Illuminate/Foundation/Application.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,9 +829,10 @@ public function registerDeferredProvider($provider, $service = null)
829829
/**
830830
* Resolve the given type from the container.
831831
*
832-
* @param string $abstract
832+
* @template T
833+
* @param class-string<T> $abstract
833834
* @param array $parameters
834-
* @return mixed
835+
* @return T|mixed
835836
*/
836837
public function make($abstract, array $parameters = [])
837838
{

src/Illuminate/Foundation/helpers.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ function action($name, $parameters = [], $absolute = true)
106106
/**
107107
* Get the available container instance.
108108
*
109-
* @param string|null $abstract
109+
* @template T
110+
* @param class-string<T>|mixed $abstract
110111
* @param array $parameters
111-
* @return mixed|\Illuminate\Contracts\Foundation\Application
112+
* @return mixed|T|\Illuminate\Contracts\Foundation\Application
112113
*/
113114
function app($abstract = null, array $parameters = [])
114115
{

0 commit comments

Comments
 (0)