This repository was archived by the owner on Mar 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 ],
You can’t perform that action at this time.
0 commit comments