Skip to content

Commit

Permalink
Review modifications.
Browse files Browse the repository at this point in the history
Signed-off-by: alexmerlin <[email protected]>
  • Loading branch information
alexmerlin committed Aug 8, 2024
1 parent ae3d204 commit ccec0e4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
14 changes: 10 additions & 4 deletions src/ConfigAggregator.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public function __construct(
return;
}

$providers = $this->removeDuplicateProviders($providers);
$providers = $this->validateDuplicateProviders($providers);
$providers = $this->preProcessProviders($preProcessors, $providers);
$this->config = $this->loadConfigFromProviders($providers);
$this->config = $this->postProcessConfig($postProcessors, $this->config);
Expand All @@ -103,13 +103,19 @@ public function getMergedConfig()
* @return ProviderIterable
* @throws InvalidConfigProviderException
*/
private function removeDuplicateProviders(iterable $providers): iterable
private function validateDuplicateProviders(iterable $providers): iterable
{
$uniqueProviders = [];

foreach ($providers as $provider) {
if (get_debug_type($provider) === 'string' && in_array($provider, $uniqueProviders, true)) {
throw InvalidConfigProviderException::fromDuplicateProvider($provider);
if (! is_string($provider) && ! is_object($provider)) {
continue;
}

if (in_array($provider, $uniqueProviders, true)) {
throw InvalidConfigProviderException::fromDuplicateProvider(
is_string($provider) ? $provider : get_debug_type($provider)
);
}

$uniqueProviders[] = $provider;
Expand Down
6 changes: 1 addition & 5 deletions src/InvalidConfigProviderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@

class InvalidConfigProviderException extends RuntimeException
{
/**
* @param string $provider
* @return self
*/
public static function fromDuplicateProvider($provider)
public static function fromDuplicateProvider(string $provider): self
{
return new self(sprintf(
'%s is registered more than once. Config providers should be unique. In case a specific order is'
Expand Down

0 comments on commit ccec0e4

Please sign in to comment.