Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
[PackageBuilder] Add parameters isset
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Sep 17, 2020
1 parent 1e84813 commit 4d36e73
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions packages/package-builder/src/Parameter/ParameterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;

/**
* @see \Symplify\PackageBuilder\Tests\Parameter\ParameterProviderTest
*/
final class ParameterProvider
{
/**
* @var mixed[]
* @var array<string, mixed>
*/
private $parameters = [];

Expand All @@ -36,15 +37,26 @@ public function provideParameter(string $name)

public function provideStringParameter(string $name): string
{
return $this->parameters[$name] ?? '';
$this->ensureParameterIsSet($name);

return $this->parameters[$name];
}

public function provideIntParameter(string $name): int
{
$this->ensureParameterIsSet($name);

return $this->parameters[$name];
}

/**
* @return mixed[]
*/
public function provideArrayParameter(string $name): array
{
return $this->parameters[$name] ?? [];
$this->ensureParameterIsSet($name);

return $this->parameters[$name];
}

public function provideBoolParameter(string $parameterName): bool
Expand All @@ -64,4 +76,13 @@ public function provide(): array
{
return $this->parameters;
}

private function ensureParameterIsSet(string $name): void
{
if (isset($this->parameters[$name])) {
return;
}

throw new ParameterNotFoundException($name);
}
}

0 comments on commit 4d36e73

Please sign in to comment.