mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 08:17:34 +00:00
FormattedCommandAlias: reduce complexity of buildCommand()
This commit is contained in:
parent
5d39d7a1c8
commit
f4d71d0b48
@ -117,18 +117,7 @@ class FormattedCommandAlias extends Command{
|
||||
throw new \InvalidArgumentException("Missing required argument " . ($position + 1));
|
||||
}
|
||||
|
||||
$replacement = "";
|
||||
if($rest && $position < count($args)){
|
||||
for($i = $position, $c = count($args); $i < $c; ++$i){
|
||||
if($i !== $position){
|
||||
$replacement .= " ";
|
||||
}
|
||||
|
||||
$replacement .= $args[$i];
|
||||
}
|
||||
}elseif($position < count($args)){
|
||||
$replacement .= $args[$position];
|
||||
}
|
||||
$replacement = self::buildReplacement($args, $position, $rest);
|
||||
|
||||
$formatString = substr($formatString, 0, $start) . $replacement . substr($formatString, $end);
|
||||
|
||||
@ -143,4 +132,25 @@ class FormattedCommandAlias extends Command{
|
||||
private static function inRange(int $i, int $j, int $k) : bool{
|
||||
return $i >= $j && $i <= $k;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string[] $args
|
||||
* @phpstan-param list<string> $args
|
||||
*/
|
||||
private static function buildReplacement(array $args, int $position, bool $rest) : string{
|
||||
$replacement = "";
|
||||
if($rest && $position < count($args)){
|
||||
for($i = $position, $c = count($args); $i < $c; ++$i){
|
||||
if($i !== $position){
|
||||
$replacement .= " ";
|
||||
}
|
||||
|
||||
$replacement .= $args[$i];
|
||||
}
|
||||
}elseif($position < count($args)){
|
||||
$replacement .= $args[$position];
|
||||
}
|
||||
|
||||
return $replacement;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user