Skip to content

Commit f1ebfd7

Browse files
committed
minor #15172 [DependencyInjection] fixed FrozenParameterBag and improved Parameter… (Tomaz Ahlin)
This PR was squashed before being merged into the 2.3 branch (closes #15172). Discussion ---------- [DependencyInjection] fixed FrozenParameterBag and improved Parameter… The ParameterBagInterface was missing some @throws annotations, so the FrozenParameterBag class was a violation of Liskov subtitution principle. Also the ParameterBagInterface was missing the remove method. (Optionally the ParameterBagInterface can be later split into two smaller interfaces, because the FrozenParameterBag shouldn't have the add, remove methods in the first place.) | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | I have also fixed removing elements from FrozenParameterBag, as introduced by @satahippy symfony/dependency-injection#8 Commits ------- 3ad0794 [DependencyInjection] fixed FrozenParameterBag and improved Parameter…
2 parents 9943fd1 + 3ad0794 commit f1ebfd7

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\DependencyInjection\ParameterBag;
1313

14+
use Symfony\Component\DependencyInjection\Exception\LogicException;
1415
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
1516

1617
/**
@@ -25,6 +26,8 @@ interface ParameterBagInterface
2526
/**
2627
* Clears all parameters.
2728
*
29+
* @throws LogicException if the ParameterBagInterface can not be cleared
30+
*
2831
* @api
2932
*/
3033
public function clear();
@@ -34,6 +37,8 @@ public function clear();
3437
*
3538
* @param array $parameters An array of parameters
3639
*
40+
* @throws LogicException if the parameter can not be added
41+
*
3742
* @api
3843
*/
3944
public function add(array $parameters);
@@ -66,6 +71,8 @@ public function get($name);
6671
* @param string $name The parameter name
6772
* @param mixed $value The parameter value
6873
*
74+
* @throws LogicException if the parameter can not be set
75+
*
6976
* @api
7077
*/
7178
public function set($name, $value);

src/Symfony/Component/DependencyInjection/Tests/ParameterBag/FrozenParameterBagTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,13 @@ public function testAdd()
5757
$bag = new FrozenParameterBag(array());
5858
$bag->add(array());
5959
}
60+
61+
/**
62+
* @expectedException \LogicException
63+
*/
64+
public function testRemove()
65+
{
66+
$bag = new FrozenParameterBag(array('foo' => 'bar'));
67+
$bag->remove('foo');
68+
}
6069
}

0 commit comments

Comments
 (0)