From 5cc0d92eff47114890a52e3c5d484531449023ec Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Tue, 10 May 2022 15:38:26 +0100 Subject: [PATCH] Fixed PHPStan errors --- src/command/SimpleCommandMap.php | 2 +- src/command/utils/CommandStringHelper.php | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/command/SimpleCommandMap.php b/src/command/SimpleCommandMap.php index 72c896c74c..548f16c39d 100644 --- a/src/command/SimpleCommandMap.php +++ b/src/command/SimpleCommandMap.php @@ -249,7 +249,7 @@ class SimpleCommandMap implements CommandMap{ foreach($commandStrings as $commandString){ $args = CommandStringHelper::parseQuoteAware($commandString); - $commandName = array_shift($args); + $commandName = array_shift($args) ?? ""; $command = $this->getCommand($commandName); if($command === null){ diff --git a/src/command/utils/CommandStringHelper.php b/src/command/utils/CommandStringHelper.php index dc5e00f8bf..7b24b3fdfc 100644 --- a/src/command/utils/CommandStringHelper.php +++ b/src/command/utils/CommandStringHelper.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace pocketmine\command\utils; +use pocketmine\utils\AssumptionFailedError; use function preg_match_all; use function preg_replace; @@ -41,7 +42,7 @@ final class CommandStringHelper{ * - `say "This is a \"string containing quotes\""` -> ['say', 'This is a "string containing quotes"'] * * @return string[] - * @phpstan-return non-empty-list + * @phpstan-return list */ public static function parseQuoteAware(string $commandLine) : array{ $args = []; @@ -49,7 +50,9 @@ final class CommandStringHelper{ foreach($matches[0] as $k => $_){ for($i = 1; $i <= 2; ++$i){ if($matches[$i][$k] !== ""){ - $args[(int) $k] = preg_replace('/\\\\([\\\\"])/u', '$1', $matches[$i][$k]); + /** @var string $match */ //phpstan can't understand preg_match and friends by itself :( + $match = $matches[$i][$k]; + $args[(int) $k] = preg_replace('/\\\\([\\\\"])/u', '$1', $match) ?? throw new AssumptionFailedError(preg_last_error_msg()); break; } }