Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve containers types to use iterable objects #299

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Next Next commit
Improve containers types to use iterable objects
  • Loading branch information
xepozz committed Apr 19, 2022
commit fa22b81fe9fa74fd953e95a615828a12bdc8905c
24 changes: 12 additions & 12 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ private function addDefinition(string $id, $definition): void
/**
* Sets multiple definitions at once.
*
* @param array $config Definitions indexed by their IDs.
* @param iterable $config Definitions indexed by their IDs.
*
* @throws InvalidConfigException
*/
private function addDefinitions(array $config): void
private function addDefinitions(iterable $config): void
vjik marked this conversation as resolved.
Show resolved Hide resolved
{
/** @var mixed $definition */
foreach ($config as $id => $definition) {
Expand All @@ -258,11 +258,11 @@ private function addDefinitions(array $config): void
* Each delegate must is a callable in format "function (ContainerInterface $container): ContainerInterface".
* The container instance returned is used in case a service can not be found in primary container.
*
* @param array $delegates
* @param iterable $delegates
*
* @throws InvalidConfigException
*/
private function setDelegates(array $delegates): void
private function setDelegates(iterable $delegates): void
vjik marked this conversation as resolved.
Show resolved Hide resolved
{
$this->delegates = new CompositeContainer();
foreach ($delegates as $delegate) {
Expand Down Expand Up @@ -327,7 +327,7 @@ private function validateDefinition($definition, ?string $id = null): void
/**
* @throws InvalidConfigException
*/
private function validateMeta(array $meta): void
private function validateMeta(iterable $meta): void
vjik marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validateMeta always receive array. Not need iterable.

{
/** @var mixed $value */
foreach ($meta as $key => $value) {
Expand Down Expand Up @@ -359,10 +359,10 @@ private function validateMeta(array $meta): void
*/
private function validateDefinitionTags($tags): void
{
if (!is_array($tags)) {
if (!is_iterable($tags)) {
throw new InvalidConfigException(
sprintf(
'Invalid definition: tags should be array of strings, %s given.',
'Invalid definition: tags should be iterable object or array of strings, %s given.',
arogachev marked this conversation as resolved.
Show resolved Hide resolved
$this->getVariableType($tags)
)
);
Expand Down Expand Up @@ -395,7 +395,7 @@ private function validateDefinitionReset($reset): void
/**
* @throws InvalidConfigException
*/
private function setTags(array $tags): void
private function setTags(iterable $tags): void
vjik marked this conversation as resolved.
Show resolved Hide resolved
{
if ($this->validate) {
foreach ($tags as $tag => $services) {
Expand All @@ -407,10 +407,10 @@ private function setTags(array $tags): void
)
);
}
if (!is_array($services)) {
if (!is_iterable($services)) {
throw new InvalidConfigException(
sprintf(
'Invalid tags configuration: tag should contain array of service IDs, %s given.',
'Invalid tags configuration: tag should be iterable object or array of service IDs, %s given.',
arogachev marked this conversation as resolved.
Show resolved Hide resolved
$this->getVariableType($services)
)
);
Expand All @@ -436,7 +436,7 @@ private function setTags(array $tags): void
/**
* @psalm-param string[] $tags
*/
private function setDefinitionTags(string $id, array $tags): void
private function setDefinitionTags(string $id, iterable $tags): void
{
foreach ($tags as $tag) {
if (!isset($this->tags[$tag]) || !in_array($id, $this->tags[$tag], true)) {
Expand Down Expand Up @@ -545,7 +545,7 @@ private function buildInternal(string $id)
* @throws CircularReferenceException
* @throws InvalidConfigException
*/
private function addProviders(array $providers): void
private function addProviders(iterable $providers): void
vjik marked this conversation as resolved.
Show resolved Hide resolved
{
$extensions = [];
/** @var mixed $provider */
Expand Down