Replace disallowed operators in src/command/

This commit is contained in:
Dylan K. Taylor 2022-01-20 16:49:58 +00:00
parent 22bc3bc3f9
commit 2f32bd877a
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
9 changed files with 19 additions and 19 deletions

View File

@ -127,7 +127,7 @@ abstract class Command{
public function testPermissionSilent(CommandSender $target, ?string $permission = null) : bool{
$permission ??= $this->permission;
if($permission === null or $permission === ""){
if($permission === null || $permission === ""){
return true;
}
@ -182,7 +182,7 @@ abstract class Command{
}
private function allowChangesFrom(CommandMap $commandMap) : bool{
return $this->commandMap === null or $this->commandMap === $commandMap;
return $this->commandMap === null || $this->commandMap === $commandMap;
}
public function isRegistered() : bool{
@ -235,7 +235,7 @@ abstract class Command{
$result = KnownTranslationFactory::chat_type_admin($source->getName(), $message);
$colored = $result->prefix(TextFormat::GRAY . TextFormat::ITALIC);
if($sendToSource and !($source instanceof ConsoleCommandSender)){
if($sendToSource && !($source instanceof ConsoleCommandSender)){
$source->sendMessage($message);
}

View File

@ -71,7 +71,7 @@ class FormattedCommandAlias extends Command{
$index = strpos($formatString, '$');
while($index !== false){
$start = $index;
if($index > 0 and $formatString[$start - 1] === "\\"){
if($index > 0 && $formatString[$start - 1] === "\\"){
$formatString = substr($formatString, 0, $start - 1) . substr($formatString, $start);
$index = strpos($formatString, '$', $index);
continue;
@ -88,7 +88,7 @@ class FormattedCommandAlias extends Command{
$argStart = $index;
while($index < strlen($formatString) and self::inRange(ord($formatString[$index]) - 48, 0, 9)){
while($index < strlen($formatString) && self::inRange(ord($formatString[$index]) - 48, 0, 9)){
++$index;
}
@ -106,19 +106,19 @@ class FormattedCommandAlias extends Command{
$rest = false;
if($index < strlen($formatString) and $formatString[$index] === "-"){
if($index < strlen($formatString) && $formatString[$index] === "-"){
$rest = true;
++$index;
}
$end = $index;
if($required and $position >= count($args)){
if($required && $position >= count($args)){
throw new \InvalidArgumentException("Missing required argument " . ($position + 1));
}
$replacement = "";
if($rest and $position < count($args)){
if($rest && $position < count($args)){
for($i = $position, $c = count($args); $i < $c; ++$i){
if($i !== $position){
$replacement .= " ";
@ -141,6 +141,6 @@ class FormattedCommandAlias extends Command{
}
private static function inRange(int $i, int $j, int $k) : bool{
return $i >= $j and $i <= $k;
return $i >= $j && $i <= $k;
}
}

View File

@ -53,7 +53,7 @@ final class PluginCommand extends Command implements PluginOwned{
$success = $this->executor->onCommand($sender, $this, $commandLabel, $args);
if(!$success and $this->usageMessage !== ""){
if(!$success && $this->usageMessage !== ""){
throw new InvalidCommandSyntaxException();
}

View File

@ -183,11 +183,11 @@ class SimpleCommandMap implements CommandMap{
private function registerAlias(Command $command, bool $isAlias, string $fallbackPrefix, string $label) : bool{
$this->knownCommands[$fallbackPrefix . ":" . $label] = $command;
if(($command instanceof VanillaCommand or $isAlias) and isset($this->knownCommands[$label])){
if(($command instanceof VanillaCommand || $isAlias) && isset($this->knownCommands[$label])){
return false;
}
if(isset($this->knownCommands[$label]) and $this->knownCommands[$label]->getLabel() === $label){
if(isset($this->knownCommands[$label]) && $this->knownCommands[$label]->getLabel() === $label){
return false;
}

View File

@ -105,7 +105,7 @@ class ClearCommand extends VanillaCommand{
];
// Checking player's inventory for all the items matching the criteria
if($targetItem !== null and $maxCount === 0){
if($targetItem !== null && $maxCount === 0){
$count = $this->countItems($inventories, $targetItem);
if($count > 0){
$sender->sendMessage(KnownTranslationFactory::commands_clear_testing($target->getName(), (string) $count));

View File

@ -96,7 +96,7 @@ class EffectCommand extends VanillaCommand{
$visible = true;
if(count($args) >= 5){
$v = strtolower($args[4]);
if($v === "on" or $v === "true" or $v === "t" or $v === "1"){
if($v === "on" || $v === "true" || $v === "t" || $v === "1"){
$visible = false;
}
}

View File

@ -52,7 +52,7 @@ class ListCommand extends VanillaCommand{
$playerNames = array_map(function(Player $player) : string{
return $player->getName();
}, array_filter($sender->getServer()->getOnlinePlayers(), function(Player $player) use ($sender) : bool{
return !($sender instanceof Player) or $sender->canSee($player);
return !($sender instanceof Player) || $sender->canSee($player);
}));
sort($playerNames, SORT_STRING);

View File

@ -181,12 +181,12 @@ class ParticleCommand extends VanillaCommand{
case "slime":
return new ItemBreakParticle(VanillaItems::SLIMEBALL());
case "itembreak":
if($data !== null and $data !== 0){
if($data !== null && $data !== 0){
return new ItemBreakParticle(ItemFactory::getInstance()->get($data));
}
break;
case "terrain":
if($data !== null and $data !== 0){
if($data !== null && $data !== 0){
return new TerrainParticle(BlockFactory::getInstance()->get($data, 0));
}
break;

View File

@ -103,7 +103,7 @@ class TimingsCommand extends VanillaCommand{
if($mode === "reset"){
TimingsHandler::reload();
Command::broadcastCommandMessage($sender, KnownTranslationFactory::pocketmine_command_timings_reset());
}elseif($mode === "merged" or $mode === "report" or $paste){
}elseif($mode === "merged" || $mode === "report" || $paste){
$timings = "";
if($paste){
$fileTimings = Utils::assumeNotFalse(fopen("php://temp", "r+b"), "Opening php://temp should never fail");
@ -154,7 +154,7 @@ class TimingsCommand extends VanillaCommand{
)],
function(array $results) use ($sender, $host) : void{
/** @phpstan-var array<InternetRequestResult|InternetException> $results */
if($sender instanceof Player and !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender
if($sender instanceof Player && !$sender->isOnline()){ // TODO replace with a more generic API method for checking availability of CommandSender
return;
}
$result = $results[0];