Fixed PHPStan errors

This commit is contained in:
Dylan K. Taylor 2022-05-10 15:38:26 +01:00
parent b875b68fc7
commit 5cc0d92eff
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
2 changed files with 6 additions and 3 deletions

View File

@ -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){

View File

@ -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<string>
* @phpstan-return list<string>
*/
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;
}
}