9
9
use Toolkit \Stdlib \Arr ;
10
10
use Toolkit \Stdlib \Str ;
11
11
use function array_shift ;
12
+ use function array_unshift ;
12
13
use function is_array ;
13
14
use function is_callable ;
14
15
use function is_int ;
@@ -205,7 +206,7 @@ protected function parseRule($rule, string $name = '', int $index = 0, bool $isO
205
206
$ rule = trim ((string )$ rule , FlagsParser::TRIM_CHARS );
206
207
207
208
// not found sep char.
208
- if (strpos ($ rule , $ sep ) === false ) {
209
+ if (! str_contains ($ rule , $ sep )) {
209
210
// has multi words, is an desc string.
210
211
if (strpos ($ rule , ' ' ) > 1 ) {
211
212
$ item ['desc ' ] = $ rule ;
@@ -216,15 +217,21 @@ protected function parseRule($rule, string $name = '', int $index = 0, bool $isO
216
217
$ limit = $ isOption ? 5 : 4 ;
217
218
$ nodes = Str::splitTrimmed ($ rule , $ sep , $ limit );
218
219
220
+ // optimize: has multi words, is an desc. auto padding type: string
221
+ if (strpos ($ nodes [0 ], ' ' ) > 1 ) {
222
+ array_unshift ($ nodes , FlagType::STRING );
223
+ }
224
+
219
225
// first is type.
220
226
$ item ['type ' ] = $ nodes [0 ];
221
- // second is required
222
- $ item [ ' required ' ] = false ;
223
- if (!empty ($ nodes [1 ])) { // desc
227
+
228
+ // second is desc
229
+ if (!empty ($ nodes [1 ])) {
224
230
$ item ['desc ' ] = $ nodes [1 ];
225
231
}
226
232
227
233
// required
234
+ $ item ['required ' ] = false ;
228
235
if (isset ($ nodes [2 ]) && ($ nodes [2 ] === 'required ' || Str::toBool ($ nodes [2 ]))) {
229
236
$ item ['required ' ] = true ;
230
237
}
0 commit comments