Skip to content

Commit 9e24331

Browse files
committed
Merge branch 'develop' into 3.x
* develop: Update regex modifiers Improvements Fix styling
2 parents 193fc30 + 6d999ab commit 9e24331

File tree

1 file changed

+7
-19
lines changed

1 file changed

+7
-19
lines changed

src/Commands/Command.php

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,15 @@ protected function parseCommandArguments(): array
168168
// Generate the regex needed to search for this pattern
169169
$regex = $this->makeRegexPattern();
170170

171-
preg_match("%{$regex[0]}%six", $this->relevantMessageSubString(), $matches);
171+
preg_match("%{$regex}%ixmu", $this->relevantMessageSubString(), $matches, PREG_UNMATCHED_AS_NULL);
172172

173-
return $this->formatMatches($matches, $regex[1]);
173+
return $this->formatMatches($matches);
174174
}
175175

176-
private function makeRegexPattern(): array
176+
private function makeRegexPattern(): string
177177
{
178178
preg_match_all(
179-
pattern: '#\{\s*(?<name>\w+)\s*(?::\s*(?<pattern>\S+)\s*)?}#',
179+
pattern: '#\{\s*(?<name>\w+)\s*(?::\s*(?<pattern>\S+)\s*)?}#ixmu',
180180
subject: $this->pattern,
181181
matches: $matches,
182182
flags: PREG_SET_ORDER
@@ -198,10 +198,7 @@ private function makeRegexPattern(): array
198198

199199
$commandName = ($this->aliases === []) ? $this->name : implode('|', [$this->name, ...$this->aliases]);
200200

201-
return [
202-
sprintf('(?:\/)%s%s%s', "(?:{$commandName})", self::OPTIONAL_BOT_NAME, $patterns->implode('\s*')),
203-
$patterns->keys()->all(),
204-
];
201+
return sprintf('(?:\/)%s%s%s', "(?:{$commandName})", self::OPTIONAL_BOT_NAME, $patterns->implode('\s*'));
205202
}
206203

207204
private function relevantMessageSubString(): string
@@ -252,18 +249,9 @@ private function cutTextFrom(Collection $splice): string
252249
);
253250
}
254251

255-
private function formatMatches(array $matches, array $argKeys): array
252+
private function formatMatches(array $matches): array
256253
{
257-
$formattedMatches = collect($matches)
258-
->filter(static fn ($match, $key): bool => is_string($key))
259-
->map(static fn ($match): string => trim($match))
260-
->filter()
261-
->all();
262-
263-
return array_merge(
264-
array_fill_keys($argKeys, null),
265-
$formattedMatches
266-
);
254+
return array_filter($matches, 'is_string', ARRAY_FILTER_USE_KEY);
267255
}
268256

269257
/**

0 commit comments

Comments
 (0)