Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f04a56

Browse files
minor #59441 [OptionResolver] Allow whitespace in types (VincentLanglet)
This PR was merged into the 7.3 branch. Discussion ---------- [OptionResolver] Allow whitespace in types | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | Fix #... | License | MIT Since we're now supporting union of type, people might prefer to use whitespace when writing union of type like `int | string` rather than `int|string`. This might be interesting for complex type, and since the support is easy I think it's a good improvement. Commits ------- 887757e Allow whitespace in types
2 parents 8dc32f7 + 887757e commit 8f04a56

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/OptionsResolver/OptionsResolver.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,7 @@ public function offsetGet(mixed $option, bool $triggerDeprecation = true): mixed
11411141

11421142
private function verifyTypes(string $type, mixed $value, ?array &$invalidTypes = null, int $level = 0): bool
11431143
{
1144+
$type = trim($type);
11441145
$allowedTypes = $this->splitOutsideParenthesis($type);
11451146
if (\count($allowedTypes) > 1) {
11461147
foreach ($allowedTypes as $allowedType) {

src/Symfony/Component/OptionsResolver/Tests/OptionsResolverTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,18 @@ public function testResolveTypedWithUnion()
790790
$this->assertSame(['foo' => '1'], $options);
791791
}
792792

793+
public function testResolveTypedWithUnionAndWhitespaces()
794+
{
795+
$this->resolver->setDefined('foo');
796+
$this->resolver->setAllowedTypes('foo', 'string | int');
797+
798+
$options = $this->resolver->resolve(['foo' => 1]);
799+
$this->assertSame(['foo' => 1], $options);
800+
801+
$options = $this->resolver->resolve(['foo' => '1']);
802+
$this->assertSame(['foo' => '1'], $options);
803+
}
804+
793805
public function testResolveTypedWithUnionOfClasse()
794806
{
795807
$this->resolver->setDefined('foo');

0 commit comments

Comments
 (0)