Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Mar 29, 2024. It is now read-only.

Commit 474dd3b

Browse files
committed
Add empty object string literal as default param value to builder
1 parent d029916 commit 474dd3b

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

‎src/Specs/Builder/ParameterSpecBuilder.php‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class ParameterSpecBuilder implements ParameterSpecBuilderInterface
5050
|
5151
(?:\[\s*\]) # empty array
5252
|
53+
(?:\{\s*\}) # empty object
54+
|
5355
true | false | null
5456
)
5557
)?
@@ -146,17 +148,28 @@ protected function buildDefaultValue(string $definition)
146148
throw new ParameterSpecBuilderException("Unknown default value format '{$definition}'");
147149
}
148150

149-
if ('[' == $definition[0] && ']' == $definition[-1]) {
151+
if ($this->wrappedWith($definition, '[', ']')) {
152+
return [];
153+
}
154+
155+
if ($this->wrappedWith($definition, '{', '}')) {
150156
return [];
151157
}
152158

153159
foreach (['"', "'"] as $quote) {
154-
if ($quote == $definition[0] && $quote == $definition[-1]) {
160+
if ($this->wrappedWith($definition, $quote, $quote)) {
155161
return trim($definition, $quote);
156162
}
157163
}
158164

159165
// Less likely we will ever get here because it should fail at a parsing step, but just in case
160166
throw new ParameterSpecBuilderException("Unknown default value format '{$definition}'");
161167
}
168+
169+
private function wrappedWith(string $definition, string $starts, $ends)
170+
{
171+
assert(strlen($definition) >= 2);
172+
173+
return $starts == $definition[0] && $ends == $definition[-1];
174+
}
162175
}

‎tests/Specs/Builder/ParameterSpecBuilderTest.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ public function provideValidDefaultValues()
162162
['1.2345', 1.2345],
163163
['[]', []],
164164
['[ ]', []],
165+
['{}', []],
166+
['{ }', []],
165167
['null', null],
166168
['Null', null],
167169
['NulL', null],

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /