From 0088ac29b16ddbf1130f27ef2eb6a2abf29fa049 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 00:38:27 +0100 Subject: [PATCH 1/7] Add generics --- src/ContainerInterface.php | 25 +++++++++++++++++++++++++ src/HasCapableInterface.php | 5 +++-- src/MapInterface.php | 1 + src/MutableContainerInterface.php | 10 +++++++--- src/WritableContainerInterface.php | 11 ++++++++--- src/WritableMapInterface.php | 3 ++- 6 files changed, 46 insertions(+), 9 deletions(-) diff --git a/src/ContainerInterface.php b/src/ContainerInterface.php index 7b0b1f4..d8cf342 100644 --- a/src/ContainerInterface.php +++ b/src/ContainerInterface.php @@ -8,9 +8,34 @@ /** * Something that can retrieve and determine the existence of a value by key. + * + * @template K of string + * @template-covariant V of mixed + * @template-extends HasCapableInterface */ interface ContainerInterface extends HasCapableInterface, BaseContainerInterface { + /** + * Finds an entry of the container by its identifier and returns it. + * + * @param K $id Identifier of the entry to look for. + * + * @return V Entry. + * + * @psalm-suppress MoreSpecificImplementedParamType The point is to narrow it. + */ + #[\Override] + public function get(string $id): mixed; + + /** + * @inheritDoc + * + * @param K $id Identifier of the entry to look for. + * + * @psalm-suppress MoreSpecificImplementedParamType The point is to narrow it. + */ + #[\Override] + public function has(string $id): bool; } diff --git a/src/HasCapableInterface.php b/src/HasCapableInterface.php index ee059be..edb0187 100644 --- a/src/HasCapableInterface.php +++ b/src/HasCapableInterface.php @@ -8,14 +8,15 @@ /** * Something that can determine the existence of a key. + * + * @template K of string */ interface HasCapableInterface { /** * Determines whether this instance has the specified key. * - * @param string $id The key to check for. - * + * @param K $id The key to check for. * @return bool True if the key exists; false otherwise. * * @throws ContainerExceptionInterface If problem determining. diff --git a/src/MapInterface.php b/src/MapInterface.php index ccb824d..17ab3bd 100644 --- a/src/MapInterface.php +++ b/src/MapInterface.php @@ -14,6 +14,7 @@ * @template TKey of string * @template-covariant TValue of mixed * @template-extends Traversable + * @template-extends ContainerInterface */ interface MapInterface extends /* @since 0.2 */ diff --git a/src/MutableContainerInterface.php b/src/MutableContainerInterface.php index 58cc2e2..6b0412e 100644 --- a/src/MutableContainerInterface.php +++ b/src/MutableContainerInterface.php @@ -10,6 +10,10 @@ /** * A container that can have mappings added and removed. * + * @template K of string + * @template V of mixed + * @template-extends ContainerInterface + * * @psalm-suppress UnusedClass */ interface MutableContainerInterface extends ContainerInterface @@ -19,8 +23,8 @@ interface MutableContainerInterface extends ContainerInterface * * @since [*next-version*] * - * @param string $key The key to map the value to. - * @param mixed $value The value to map to the key. + * @param K $key The key to map the value to. + * @param V $value The value to map to the key. * * @throws ContainerExceptionInterface If problem mapping. * @psalm-suppress InvalidThrow @@ -32,7 +36,7 @@ public function set(string $key, $value): void; * * @since [*next-version*] * - * @param string $key The key to unmap the value from. + * @param K $key The key to unmap the value from. * * @throws NotFoundExceptionInterface If key not found. * @throws ContainerExceptionInterface If problem unmapping. diff --git a/src/WritableContainerInterface.php b/src/WritableContainerInterface.php index c811fbf..ce4cd41 100644 --- a/src/WritableContainerInterface.php +++ b/src/WritableContainerInterface.php @@ -8,6 +8,11 @@ /** * A container that can be written to. + * + * @template K of string + * @template V of mixed + * + * @template-extends ContainerInterface */ interface WritableContainerInterface extends ContainerInterface { @@ -16,7 +21,7 @@ interface WritableContainerInterface extends ContainerInterface * * @since [*next-version*] * - * @param array $mappings A map of keys to values. + * @param array $mappings A map of keys to values. * * @return static A new instance of this class with only the specified key-value mappings. * @@ -31,7 +36,7 @@ public function withMappings(array $mappings): WritableContainerInterface; * * @since [*next-version*] * - * @param array $mappings A map of keys to values. + * @param array $mappings A map of keys to values. * * @return static A new instance of this class with the specified key-value mappings added to existing ones. * @@ -46,7 +51,7 @@ public function withAddedMappings(array $mappings): WritableContainerInterface; * * @since [*next-version*] * - * @param array $keys The keys to exclude. + * @param array $keys The keys to exclude. * * @return static A new instance of this class which does not contain the specified keys. * diff --git a/src/WritableMapInterface.php b/src/WritableMapInterface.php index 0bd7ced..5663d54 100644 --- a/src/WritableMapInterface.php +++ b/src/WritableMapInterface.php @@ -10,8 +10,9 @@ * @since [*next-version*] * * @template TKey of string - * @template-covariant TValue of mixed + * @template TValue of mixed * @template-extends MapInterface + * @template-extends WritableContainerInterface */ interface WritableMapInterface extends MapInterface, WritableContainerInterface { From e5df5b3d45c1dd0e1720bb943fda2ac0fa6be54a Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 00:40:38 +0100 Subject: [PATCH 2/7] Add param type hint --- src/MutableContainerInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MutableContainerInterface.php b/src/MutableContainerInterface.php index 6b0412e..fcf0232 100644 --- a/src/MutableContainerInterface.php +++ b/src/MutableContainerInterface.php @@ -29,7 +29,7 @@ interface MutableContainerInterface extends ContainerInterface * @throws ContainerExceptionInterface If problem mapping. * @psalm-suppress InvalidThrow */ - public function set(string $key, $value): void; + public function set(string $key, mixed $value): void; /** * Unmaps the value from the specified key. From d4725e39d714d7d51de0ebcd9372e220dc1ec08a Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 00:43:55 +0100 Subject: [PATCH 3/7] Unsuppress `InvalidThrow`: useless The PSR-11 exceptions now `extends Throwable`. --- src/ClearableContainerInterface.php | 1 - src/HasCapableInterface.php | 1 - src/MutableContainerInterface.php | 2 -- 3 files changed, 4 deletions(-) diff --git a/src/ClearableContainerInterface.php b/src/ClearableContainerInterface.php index bfcacaf..077982a 100644 --- a/src/ClearableContainerInterface.php +++ b/src/ClearableContainerInterface.php @@ -12,7 +12,6 @@ interface ClearableContainerInterface extends PsrContainerInterface /** * Removes all members from this container. * - * @psalm-suppress InvalidThrow In PSR-11, this interface does not extend `Throwable`. * @throws ContainerExceptionInterface If problem removing. */ public function clear(): void; diff --git a/src/HasCapableInterface.php b/src/HasCapableInterface.php index edb0187..ecd3271 100644 --- a/src/HasCapableInterface.php +++ b/src/HasCapableInterface.php @@ -22,7 +22,6 @@ interface HasCapableInterface * @throws ContainerExceptionInterface If problem determining. * * @psalm-suppress PossiblyUnusedMethod - * @psalm-suppress InvalidThrow */ public function has(string $id): bool; } diff --git a/src/MutableContainerInterface.php b/src/MutableContainerInterface.php index fcf0232..7b089ed 100644 --- a/src/MutableContainerInterface.php +++ b/src/MutableContainerInterface.php @@ -27,7 +27,6 @@ interface MutableContainerInterface extends ContainerInterface * @param V $value The value to map to the key. * * @throws ContainerExceptionInterface If problem mapping. - * @psalm-suppress InvalidThrow */ public function set(string $key, mixed $value): void; @@ -40,7 +39,6 @@ public function set(string $key, mixed $value): void; * * @throws NotFoundExceptionInterface If key not found. * @throws ContainerExceptionInterface If problem unmapping. - * @psalm-suppress InvalidThrow */ public function unset(string $key): void; } From 6829407fd805fceb00424754c2df5fae42f1f2ce Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 00:59:05 +0100 Subject: [PATCH 4/7] Declare typehint --- src/HasItemCapableInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HasItemCapableInterface.php b/src/HasItemCapableInterface.php index 51f4089..cf02443 100644 --- a/src/HasItemCapableInterface.php +++ b/src/HasItemCapableInterface.php @@ -28,5 +28,5 @@ interface HasItemCapableInterface * * @psalm-suppress PossiblyUnusedMethod */ - public function hasItem($item): bool; + public function hasItem(mixed $item): bool; } From 476dd0eeb20b2963517a6dfc939e52e634f3cc6b Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 01:07:29 +0100 Subject: [PATCH 5/7] Declare typehint --- src/WritableContainerFactoryInterface.php | 9 ++++++++- src/WritableMapFactoryInterface.php | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/WritableContainerFactoryInterface.php b/src/WritableContainerFactoryInterface.php index 26ca2d3..364ea17 100644 --- a/src/WritableContainerFactoryInterface.php +++ b/src/WritableContainerFactoryInterface.php @@ -14,7 +14,14 @@ interface WritableContainerFactoryInterface extends ContainerFactoryInterface /** * @inheritDoc * - * @return WritableContainerInterface The new container. + * @template K of string + * @template V of mixed + * + * @param array $data The data for the container. + * + * @return WritableContainerInterface The new container. + * + * @psalm-suppress MoreSpecificImplementedParamType PSR-11 does not declare generics, but should */ #[\Override] public function createContainerFromArray(array $data): ContainerInterface; diff --git a/src/WritableMapFactoryInterface.php b/src/WritableMapFactoryInterface.php index ba5f241..fc25c3f 100644 --- a/src/WritableMapFactoryInterface.php +++ b/src/WritableMapFactoryInterface.php @@ -14,7 +14,14 @@ interface WritableMapFactoryInterface extends WritableContainerFactoryInterface, /** * @inheritDoc * - * @return WritableMapInterface The new map. + * @template K of string + * @template V of mixed + * + * @param array $data The data for the container. + * + * @return WritableMapInterface The new container. + * + * @psalm-suppress MoreSpecificImplementedParamType PSR-11 does not declare generics, but should */ #[\Override] public function createContainerFromArray(array $data): WritableMapInterface; From 98feab5bd2aa702b5114a8034c2dba39b90b2a9c Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 01:07:46 +0100 Subject: [PATCH 6/7] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3c8f01b..86e2335 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [[*next-version*]] - YYYY-MM-DD ### Changed - Aligned param names with those of PSR interfaces (#37). +- Added more generics (#38). ## [0.5.0-beta1] - 2026-03-23 ### Changed From 551d7e50b0c0eaed2612933f1bd2ac8245bb6507 Mon Sep 17 00:00:00 2001 From: Anton Ukhanev Date: Tue, 24 Mar 2026 01:11:35 +0100 Subject: [PATCH 7/7] Normalize line endings --- .gitattributes | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitattributes b/.gitattributes index 79b6111..46bb334 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,3 +1,6 @@ +# Set default behavior to automatically normalize line endings to LF on all text files. +* text eol=lf + test export-ignore nbproject export-ignore .idea export-ignore