Skip to content

Commit

Permalink
feat: phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
hschoenenberger committed Dec 24, 2024
1 parent 8296ac1 commit bb38ca2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
23 changes: 6 additions & 17 deletions src/ServiceContainer/ServiceContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,21 @@ public function has($name)

/**
* @param string $name
* @param mixed $default
*
* @return string
* @return mixed
*
* @throws ParameterNotFoundException
*/
public function getParameter($name)
public function getParameter($name, $default = null)
{
if (array_key_exists($name, $this->config)) {
return $this->config[$name];
}
throw new ParameterNotFoundException('Configuration parameter "' . $name . '" not found.');
}

/**
* @param string $name
* @param string $default
*
* @return string
*/
public function getParameterWithDefault($name, $default)
{
if (array_key_exists($name, $this->config)) {
return $this->config[$name];
if (func_num_args() > 1) {
return $default;
}

return $default;
throw new ParameterNotFoundException('Configuration parameter "' . $name . '" not found.');
}

/**
Expand Down
15 changes: 13 additions & 2 deletions tests/src/ServiceContainer/ServiceContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ public function itShouldGetParameterDefaultValue()
$default = 'foo';

$this->assertFalse($this->container->hasParameter('not_found'));
$this->assertEquals($default, $this->container->getParameterWithDefault('not_found', $default));
$this->assertEquals($default, $this->container->getParameter('not_found', $default));
}

/**
* @test
*/
public function itShouldGetParameterDefaultNullValue()
{
$default = null;

$this->assertFalse($this->container->hasParameter('not_found'));
$this->assertEquals($default, $this->container->getParameter('not_found', $default));
}

/**
Expand All @@ -67,7 +78,7 @@ public function itShouldNotGetParameterDefaultValue()
$default = 'foo';

$this->assertTrue($this->container->hasParameter('log_level'));
$this->assertEquals('DEBUG', $this->container->getParameterWithDefault('log_level', $default));
$this->assertEquals('DEBUG', $this->container->getParameter('log_level', $default));
}

/**
Expand Down

0 comments on commit bb38ca2

Please sign in to comment.