8000 minor #58363 [DependencyInjection] Rename non-empty parameter methods… · symfony/symfony@082c586 · GitHub
[go: up one dir, main page]

Skip to content

Commit 082c586

Browse files
minor #58363 [DependencyInjection] Rename non-empty parameter methods (yceruto)
This PR was merged into the 7.2 branch. Discussion ---------- [DependencyInjection] Rename non-empty parameter methods | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT After an internal discussion we are proposing to rename the main methods of this feature to make them clearer. New names: ```php $parameterBag->cannotBeEmpty(...); $containerBuilder->parameterCannotBeEmpty(...); ``` Commits ------- 5fa7c31 rename non-empty parameter methods
2 parents 2ffd266 + 5fa7c31 commit 082c586

File tree

7 files changed

+25
-13
lines changed

7 files changed

+25
-13
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ public function load(array $configs, ContainerBuilder $container): void
309309
if (isset($config['secret'])) {
310310
$container->setParameter('kernel.secret', $config['secret']);
311311
}
312-
$container->nonEmptyParameter('kernel.secret', 'A non-empty value for the parameter "kernel.secret" is required. Did you forget to configure the "framework.secret" option?');
312+
$container->parameterCannotBeEmpty('kernel.secret', 'A non-empty value for the parameter "kernel.secret" is required. Did you forget to configure the "framework.secret" option?');
313313

314314
$container->setParameter('kernel.http_method_override', $config['http_method_override']);
315315
$container->setParameter('kernel.trust_x_sendfile_type_header', $config['trust_x_sendfile_type_header']);

src/Symfony/Component/DependencyInjection/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CHANGELOG
77
* Deprecate `!tagged` tag, use `!tagged_iterator` instead
88
* Add a `ContainerBuilder::registerChild()` shortcut method for registering child definitions
99
* Add support for `key-type` in `XmlFileLoader`
10-
* Enable non-empty parameters with `ParameterBag::nonEmpty()` and `ContainerBuilder::nonEmptyParameter()` methods
10+
* Enable non-empty parameters with `ParameterBag::cannotBeEmpty()` and `ContainerBuilder::parameterCannotBeEmpty()` methods
1111

1212
7.1
1313
---

src/Symfony/Component/DependencyInjection/ContainerBuilder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ public function merge(self $container): void
673673
}
674674

675675
foreach ($otherBag->allNonEmpty() as $name => $message) {
676-
$parameterBag->nonEmpty($name, $message);
676+
$parameterBag->cannotBeEmpty($name, $message);
677677
}
678678
}
679679

@@ -768,13 +768,13 @@ public function deprecateParameter(string $name, string $package, string $versio
768768
$this->parameterBag->deprecate($name, $package, $version, $message);
769769
}
770770

771-
public function nonEmptyParameter(string $name, string $message): void
771+
public function parameterCannotBeEmpty(string $name, string $message): void
772772
{
773773
if (!$this->parameterBag instanceof ParameterBag) {
774774
throw new BadMethodCallException(\sprintf('The parameter bag must be an instance of "%s" to call "%s()".', ParameterBag::class, __METHOD__));
775775
}
776776

777-
$this->parameterBag->nonEmpty($name, $message);
777+
$this->parameterBag->cannotBeEmpty($name, $message);
778778
}
779779

780780
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public function deprecate(string $name, string $package, string $version, string
5555
throw new LogicException('Impossible to call deprecate() on a frozen ParameterBag.');
5656
}
5757

58-
public function nonEmpty(string $name, string $message = 'A non-empty parameter "%s" is required.'): never
58+
public function cannotBeEmpty(string $name, string $message = 'A non-empty parameter "%s" is required.'): never
5959
{
60-
throw new LogicException('Impossible to call nonEmpty() on a frozen ParameterBag.');
60+
throw new LogicException('Impossible to call cannotBeEmpty() on a frozen ParameterBag.');
6161
}
6262

6363
public function remove(string $name): never

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ public function deprecate(string $name, string $package, string $version, string
133133
$this->deprecatedParameters[$name] = [$package, $version, $message, $name];
134134
}
135135

136-
public function nonEmpty(string $name, string $message): void
136+
public function cannotBeEmpty(string $name, string $message): void
137137
{
138138
$this->nonEmptyParameters[$name] = $message;
139139
}

src/Symfony/Component/DependencyInjection/Tests/Fixtures/containers/container_nonempty_parameters.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use Symfony\Component\DependencyInjection\Parameter;
55

66
$container = new ContainerBuilder();
7-
$container->nonEmptyParameter('bar', 'Did you forget to configure the "foo.bar" option?');
7+
$container->parameterCannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
88
$container->register('foo', 'stdClass')
99
->setArguments([new Parameter('bar')])
1010
->setPublic(true)

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Bridge\PhpUnit\ExpectUserDeprecationMessageTrait;
16-
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1716
use Symfony\Component\DependencyInjection\Exception\EmptyParameterValueException;
17+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1818
use Symfony\Component\DependencyInjection\Exception\ParameterCircularReferenceException;
1919
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
2020
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@@ -201,7 +201,7 @@ public function testGetMissingRequiredParameter()
201201
{
202202
$bag = new ParameterBag();
203203

204-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
204+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
205205

206206
$this->expectException(ParameterNotFoundException::class);
207207
$this->expectExceptionMessage('You have requested a non-existent parameter "bar". Did you forget to configure the "foo.bar" option?');
@@ -213,7 +213,7 @@ public function testGetNonEmptyParameterThrowsWhenNullValue()
213213
{
214214
$bag = new ParameterBag();
215215
$bag->set('bar', null);
216-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
216+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
217217

218218
$this->expectException(EmptyParameterValueException::class);
219219
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');
@@ -225,7 +225,19 @@ public function testGetNonEmptyParameterThrowsWhenEmptyStringValue()
225225
{
226226
$bag = new ParameterBag();
227227
$bag->set('bar', '');
228-
$bag->nonEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
228+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
229+
230+
$this->expectException(EmptyParameterValueException::class);
231+
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');
232+
233+
$bag->get('bar');
234+
}
235+
236+
public function testGetNonEmptyParameterThrowsWhenEmptyArrayValue()
237+
{
238+
$bag = new ParameterBag();
239+
$bag->set('bar', []);
240+
$bag->cannotBeEmpty('bar', 'Did you forget to configure the "foo.bar" option?');
229241

230242
$this->expectException(EmptyParameterValueException::class);
231243
$this->expectExceptionMessage('Did you forget to configure the "foo.bar" option?');

0 commit comments

Comments
 (0)
0