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 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 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/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..ecd3271 100644 --- a/src/HasCapableInterface.php +++ b/src/HasCapableInterface.php @@ -8,20 +8,20 @@ /** * 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. * * @psalm-suppress PossiblyUnusedMethod - * @psalm-suppress InvalidThrow */ public function has(string $id): bool; } 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; } 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..7b089ed 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,24 +23,22 @@ 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 */ - public function set(string $key, $value): void; + public function set(string $key, mixed $value): void; /** * Unmaps the value from the specified key. * * @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. - * @psalm-suppress InvalidThrow */ public function unset(string $key): void; } 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/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/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; 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 {