From a34d109612e4e4e9acf28c78df4a40ceb7f26165 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 11 Jan 2024 10:37:40 +0100 Subject: [PATCH 1/4] Add generics to ContainerInterface --- src/ContainerInterface.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index b2cad40..dd8fcae 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -12,12 +12,14 @@ interface ContainerInterface /** * Finds an entry of the container by its identifier and returns it. * - * @param string $id Identifier of the entry to look for. + * @template T of mixed + * + * @param T|string $id Identifier of the entry to look for. * * @throws NotFoundExceptionInterface No entry was found for **this** identifier. * @throws ContainerExceptionInterface Error while retrieving the entry. * - * @return mixed Entry. + * @return T|mixed Entry. */ public function get(string $id); From 40d0b06d3157a68abf5a8887b9e71c5ee13f9caf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 11 Jan 2024 10:42:05 +0100 Subject: [PATCH 2/4] Update src/ContainerInterface.php Co-authored-by: Mathias Arlaud --- src/ContainerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index dd8fcae..7742ab6 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -14,7 +14,7 @@ interface ContainerInterface * * @template T of mixed * - * @param T|string $id Identifier of the entry to look for. + * @param class-string|string $id Identifier of the entry to look for. * * @throws NotFoundExceptionInterface No entry was found for **this** identifier. * @throws ContainerExceptionInterface Error while retrieving the entry. From 6ce72694d0e2452d56a50555c034ca91d93dd551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Thu, 11 Jan 2024 10:43:34 +0100 Subject: [PATCH 3/4] Fix template --- src/ContainerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index 7742ab6..caf6654 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -12,7 +12,7 @@ interface ContainerInterface /** * Finds an entry of the container by its identifier and returns it. * - * @template T of mixed + * @template T of object * * @param class-string|string $id Identifier of the entry to look for. * From decd4d1cd85408f005bfe65d02fc650f012abc9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Fr=C3=A9mont?= Date: Mon, 5 Feb 2024 11:55:45 +0100 Subject: [PATCH 4/4] Apply suggestions from code review --- src/ContainerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index caf6654..fdc1c08 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -19,7 +19,7 @@ interface ContainerInterface * @throws NotFoundExceptionInterface No entry was found for **this** identifier. * @throws ContainerExceptionInterface Error while retrieving the entry. * - * @return T|mixed Entry. + * @return ($id is class-string ? T : mixed) Entry. */ public function get(string $id);