Skip to content

Commit

Permalink
Align signatures with Container Interop v2
Browse files Browse the repository at this point in the history
  • Loading branch information
XedinUnknown committed Sep 21, 2024
1 parent e0a2bd2 commit a8ce109
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 181 deletions.
10 changes: 2 additions & 8 deletions src/AliasingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,17 @@ public function __construct(PsrContainerInterface $inner, array $aliases)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function get($key)
public function get(string $key)
{
return $this->inner->get($this->getInnerKey($key));
}

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return $this->inner->has($this->getInnerKey($key));
}

Expand Down
15 changes: 2 additions & 13 deletions src/CachingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ public function __construct(PsrContainerInterface $container)
/**
* {@inheritDoc}
*/
public function get($key)
public function get(string $key)
{
/** @psalm-suppress RedundantCastGivenDocblockType
* @psalm-suppress RedundantCast
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

/**
* @psalm-suppress InvalidCatch
* The base interface does not extend Throwable, but in fact everything that is possible
Expand Down Expand Up @@ -76,13 +70,8 @@ public function get($key)
/**
* {@inheritDoc}
*/
public function has($key)
public function has(string $key): bool
{
/** @psalm-suppress RedundantCastGivenDocblockType
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

/**
* @psalm-suppress InvalidCatch
* The base interface does not extend Throwable, but in fact everything that is possible
Expand Down
17 changes: 2 additions & 15 deletions src/CompositeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Exception;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Traversable;
use UnexpectedValueException;

class CompositeContainer implements ContainerInterface
{
Expand All @@ -34,14 +32,8 @@ public function __construct(iterable $containers)
/**
* {@inheritDoc}
*/
public function get($key)
public function get(string $key)
{
/** @psalm-suppress RedundantCastGivenDocblockType
* @psalm-suppress RedundantCast
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

foreach ($this->containers as $index => $container) {
/**
* @psalm-suppress InvalidCatch
Expand Down Expand Up @@ -77,13 +69,8 @@ public function get($key)
/**
* {@inheritDoc}
*/
public function has($key)
public function has(string $key): bool
{
/** @psalm-suppress RedundantCastGivenDocblockType
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

foreach ($this->containers as $index => $container) {
try {
if ($container->has($key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/DataStructureBasedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Dhii\Container;

use Dhii\Collection\WritableMapFactoryInterface;
use Psr\Container\ContainerInterface;
use Dhii\Collection\WritableMapInterface;

/**
* @inheritDoc
Expand All @@ -24,7 +24,7 @@ public function __construct(WritableMapFactoryInterface $containerFactory)
/**
* @inheritDoc
*/
public function createContainerFromArray(array $structure): ContainerInterface
public function createContainerFromArray(array $structure): WritableMapInterface
{
$map = [];
foreach ($structure as $key => $value) {
Expand Down
3 changes: 1 addition & 2 deletions src/DataStructureBasedFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Dhii\Collection\WritableMapFactoryInterface;
use Dhii\Collection\WritableMapInterface;
use Exception;
use Psr\Container\ContainerInterface as BaseContainerInterface;

/**
* Creates a container hierarchy based on a traditional data structure.
Expand All @@ -23,5 +22,5 @@ interface DataStructureBasedFactoryInterface extends WritableMapFactoryInterface
*
* @throws Exception If problem creating.
*/
public function createContainerFromArray(array $structure): BaseContainerInterface;
public function createContainerFromArray(array $structure): WritableMapInterface;
}
5 changes: 2 additions & 3 deletions src/DelegatingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ServiceProviderInterface $provider, PsrContainerInte
/**
* {@inheritDoc}
*/
public function get($id)
public function get(string $id)
{
if (array_key_exists($id, $this->stack)) {
$trace = implode(' -> ', array_keys($this->stack)) . ' -> ' . $id;
Expand All @@ -67,10 +67,9 @@ public function get($id)
/**
* {@inheritDoc}
*/
public function has($id)
public function has(string $id): bool
{
$services = $this->provider->getFactories();
$id = (string) $id;

return array_key_exists($id, $services);
}
Expand Down
11 changes: 2 additions & 9 deletions src/DeprefixingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ public function __construct(PsrContainerInterface $container, string $prefix, bo

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function get($key)
public function get(string $key)
{
/**
* @psalm-suppress InvalidCatch
Expand All @@ -79,12 +77,9 @@ public function get($key)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;
$realKey = $this->getInnerKey($key);

return $this->inner->has($realKey) || (!$this->strict && $this->inner->has($key));
Expand All @@ -93,8 +88,6 @@ public function has($key)
/**
* Retrieves the key to use for the inner container.
*
* @since [*next-version*]
*
* @param string $key The outer key.
*
* @return string The inner key.
Expand Down
6 changes: 2 additions & 4 deletions src/Dictionary.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(array $data)
/**
* {@inheritDoc}
*/
public function get($key)
public function get(string $key)
{
if (!array_key_exists($key, $this->data)) {
throw new NotFoundException(
Expand All @@ -52,10 +52,8 @@ public function get($key)
/**
* {@inheritDoc}
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

$isHas = array_key_exists($key, $this->data);

return $isHas;
Expand Down
4 changes: 2 additions & 2 deletions src/DictionaryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Dhii\Container;

use Dhii\Collection\WritableMapFactoryInterface;
use Psr\Container\ContainerInterface;
use Dhii\Collection\WritableMapInterface;

/**
* @inheritDoc
Expand All @@ -15,7 +15,7 @@ class DictionaryFactory implements WritableMapFactoryInterface
/**
* @inheritDoc
*/
public function createContainerFromArray(array $data): ContainerInterface
public function createContainerFromArray(array $data): WritableMapInterface
{
return new Dictionary($data);
}
Expand Down
7 changes: 2 additions & 5 deletions src/FlashContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Dhii\Collection\ClearableContainerInterface;
use Dhii\Collection\MutableContainerInterface;
use Dhii\Container\Exception\NotFoundException;
use Psr\Container\ContainerExceptionInterface;

/**
* A container for data that is accessible once per init.
Expand Down Expand Up @@ -59,10 +58,8 @@ public function init(): void
/**
* @inheritDoc
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return array_key_exists($key, $this->flashData);
}

Expand All @@ -71,7 +68,7 @@ public function has($key)
*
* Retrieves the value for the specified key from memory.
*/
public function get($key)
public function get(string $key)
{
if (!array_key_exists($key, $this->flashData)) {
throw new NotFoundException(sprintf('Flash data not found for key "%1$s"', $key));
Expand Down
10 changes: 2 additions & 8 deletions src/HierarchyContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,8 @@ public function __construct(array $data)

/**
* @inheritDoc
*
* @since [*next-version*]
*/
public function get($key)
public function get(string $key)
{
if (!array_key_exists($key, $this->data)) {
throw new NotFoundException("Key '{$key}' does not exist", 0, null);
Expand All @@ -83,13 +81,9 @@ public function get($key)

/**
* @inheritDoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return array_key_exists($key, $this->data);
}
}
25 changes: 3 additions & 22 deletions src/MappingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,15 @@
*/
class MappingContainer implements ContainerInterface
{
/* @since [*next-version*] */
use StringTranslatingTrait;

/**
* @since [*next-version*]
*
* @var callable
*/
/** @var callable */
protected $callback;

/**
* @since [*next-version*]
*
* @var PsrContainerInterface
*/
/** @var PsrContainerInterface */
protected $inner;

/**
* Constructor.
*
* @since [*next-version*]
*
* @param PsrContainerInterface $inner The container instance to decorate.
* @param callable $callback The callback to invoke on get. It will be passed 3 parameters:
* * The inner container's value for the key being fetched.
Expand All @@ -70,8 +57,6 @@ public function __construct(PsrContainerInterface $inner, callable $callback)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function get($key)
{
Expand All @@ -80,13 +65,9 @@ public function get($key)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return $this->inner->has($key);
}
}
17 changes: 2 additions & 15 deletions src/MaskingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@

/**
* An implementation of a container that wraps around another to selectively expose or mask certain keys.
*
* @since [*next-version*]
*/
class MaskingContainer implements ContainerInterface
{
/* @since [*next-version*] */
use StringTranslatingTrait;

/**
Expand All @@ -39,8 +36,6 @@ class MaskingContainer implements ContainerInterface
/**
* Constructor.
*
* @since [*next-version*]
*
* @param PsrContainerInterface $inner The container whose entries to mask.
* @param bool $defaultMask The default mask. If true, all inner keys are exposed. If false, all
* inner keys are hidden. Any keys specified in the $mask parameter will
Expand All @@ -57,10 +52,8 @@ public function __construct(PsrContainerInterface $inner, bool $defaultMask, arr

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function get($key)
public function get(string $key)
{
if (!$this->isExposed($key)) {
throw new NotFoundException(
Expand All @@ -75,21 +68,15 @@ public function get($key)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return $this->isExposed($key) && $this->inner->has($key);
}

/**
* Checks if a key is exposed through the mask.
*
* @since [*next-version*]
*
* @param string $key The key to check.
*
* @return bool True if the key is exposed, false if the key is hidden.
Expand Down
Loading

0 comments on commit a8ce109

Please sign in to comment.