Skip to content

Commit c165362

Browse files
committed
optimize: has multi words, is an desc. auto padding type: string
1 parent 00c33bf commit c165362

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

.github/workflows/php.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ jobs:
6464
if: ${{ matrix.php == '7.4' }}
6565
run: |
6666
wget -c -q https://github.com/inhere/kite/releases/latest/download/kite.phar
67-
php kite.phar git cl last head --style gh-release --no-merges --fetch-tags --unshallow --file changelog.md
68-
cat changelog.md
67+
php kite.phar git cl last head --style gh-release --no-merges --fetch-tags --unshallow --file example/changelog.md
68+
cat example/changelog.md
6969
7070
# phpunit -v --debug
7171
# phpdbg -dauto_globals_jit=Off-qrr $(which phpunit) --coverage-clover ./test/clover.info

example/changelog.md

Whitespace-only changes.

src/Concern/RuleParserTrait.php

+11-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Toolkit\Stdlib\Arr;
1010
use Toolkit\Stdlib\Str;
1111
use function array_shift;
12+
use function array_unshift;
1213
use function is_array;
1314
use function is_callable;
1415
use function is_int;
@@ -205,7 +206,7 @@ protected function parseRule($rule, string $name = '', int $index = 0, bool $isO
205206
$rule = trim((string)$rule, FlagsParser::TRIM_CHARS);
206207

207208
// not found sep char.
208-
if (strpos($rule, $sep) === false) {
209+
if (!str_contains($rule, $sep)) {
209210
// has multi words, is an desc string.
210211
if (strpos($rule, ' ') > 1) {
211212
$item['desc'] = $rule;
@@ -216,15 +217,21 @@ protected function parseRule($rule, string $name = '', int $index = 0, bool $isO
216217
$limit = $isOption ? 5 : 4;
217218
$nodes = Str::splitTrimmed($rule, $sep, $limit);
218219

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+
219225
// first is type.
220226
$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])) {
224230
$item['desc'] = $nodes[1];
225231
}
226232

227233
// required
234+
$item['required'] = false;
228235
if (isset($nodes[2]) && ($nodes[2] === 'required' || Str::toBool($nodes[2]))) {
229236
$item['required'] = true;
230237
}

0 commit comments

Comments
 (0)