eliminate remaining empty() usages

This commit is contained in:
Dylan K. Taylor 2020-02-07 21:46:16 +00:00
parent 1ffabbb567
commit aac7da6c96
22 changed files with 40 additions and 30 deletions

View File

@ -79,7 +79,7 @@ abstract class BaseRail extends Flowable{
}
protected function writeStateToMeta() : int{
if(empty($this->connections)){
if(count($this->connections) === 0){
return BlockLegacyMetadata::RAIL_STRAIGHT_NORTH_SOUTH;
}
return $this->getMetaForState($this->connections);

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use function count;
class Fence extends Transparent{
/** @var bool[] facing => dummy */
@ -80,7 +81,7 @@ class Fence extends Transparent{
->trim(Facing::SOUTH, $connectSouth ? 0 : $inset);
}
if(empty($bbs)){
if(count($bbs) === 0){
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
return [
AxisAlignedBB::one()

View File

@ -25,6 +25,7 @@ namespace pocketmine\block;
use pocketmine\math\AxisAlignedBB;
use pocketmine\math\Facing;
use function count;
class Thin extends Transparent{
/** @var bool[] facing => dummy */
@ -71,7 +72,7 @@ class Thin extends Transparent{
$bbs[] = $bb;
}
if(empty($bbs)){
if(count($bbs) === 0){
//centre post AABB (only needed if not connected on any axis - other BBs overlapping will do this if any connections are made)
return [
AxisAlignedBB::one()->contract($inset, 0, $inset)

View File

@ -30,6 +30,7 @@ use pocketmine\math\Vector3;
use pocketmine\player\Player;
use pocketmine\world\BlockTransaction;
use function array_intersect_key;
use function count;
class Vine extends Flowable{
@ -113,7 +114,7 @@ class Vine extends Flowable{
}
if($changed){
if(empty($this->faces)){
if(count($this->faces) === 0){
$this->pos->getWorld()->useBreakOn($this->pos);
}else{
$this->pos->getWorld()->setBlock($this->pos, $this);

View File

@ -644,7 +644,7 @@ abstract class Entity{
$this->justCreated = false;
$changedProperties = $this->getSyncedNetworkData(true);
if(!empty($changedProperties)){
if(count($changedProperties) > 0){
$this->sendData($this->hasSpawned, $changedProperties);
$this->networkProperties->clearDirtyProperties();
}

View File

@ -31,6 +31,7 @@ use pocketmine\world\sound\XpCollectSound;
use pocketmine\world\sound\XpLevelUpSound;
use function array_rand;
use function ceil;
use function count;
use function max;
use function min;
@ -251,7 +252,7 @@ class ExperienceManager{
}
}
if(!empty($equipment)){
if(count($equipment) > 0){
$repairItem = $equipment[$k = array_rand($equipment)];
if($repairItem->getDamage() > 0){
$repairAmount = min($repairItem->getDamage(), $xpValue * 2);

View File

@ -186,7 +186,7 @@ abstract class Living extends Entity{
$nbt->setShort("Air", $this->getAirSupplyTicks());
if(!empty($this->effectManager->all())){
if(count($this->effectManager->all()) > 0){
$effects = [];
foreach($this->effectManager->all() as $effect){
$effects[] = CompoundTag::create()

View File

@ -29,6 +29,7 @@ use pocketmine\event\entity\EntityEffectRemoveEvent;
use pocketmine\utils\Color;
use pocketmine\utils\Utils;
use function abs;
use function count;
use function spl_object_id;
class EffectManager{
@ -188,7 +189,7 @@ class EffectManager{
}
}
if(!empty($colors)){
if(count($colors) > 0){
$this->bubbleColor = Color::mix(...$colors);
$this->onlyAmbientEffects = $ambient;
}else{
@ -217,7 +218,7 @@ class EffectManager{
}
}
return !empty($this->effects);
return count($this->effects) > 0;
}
/**

View File

@ -26,6 +26,7 @@ namespace pocketmine\event\player;
use pocketmine\event\Event;
use pocketmine\player\PlayerInfo;
use function array_keys;
use function count;
/**
* Called when a player connects to the server, prior to authentication taking place.
@ -139,7 +140,7 @@ class PlayerPreLoginEvent extends Event{
* Returns whether the player is allowed to continue logging in.
*/
public function isAllowed() : bool{
return empty($this->kickReasons);
return count($this->kickReasons) === 0;
}
/**

View File

@ -48,6 +48,7 @@ use pocketmine\utils\Binary;
use pocketmine\utils\Utils;
use function base64_decode;
use function base64_encode;
use function count;
use function get_class;
use function gettype;
use function hex2bin;
@ -326,7 +327,7 @@ class Item implements \JsonSerializable{
$display->setString(self::TAG_DISPLAY_NAME, $this->getCustomName()) :
$display->removeTag(self::TAG_DISPLAY);
if(!empty($this->lore)){
if(count($this->lore) > 0){
$loreTag = new ListTag();
foreach($this->lore as $line){
$loreTag->push(new StringTag($line));

View File

@ -25,6 +25,7 @@ namespace pocketmine\item;
use pocketmine\item\enchantment\Enchantment;
use pocketmine\item\enchantment\EnchantmentInstance;
use function count;
/**
* This trait encapsulates all enchantment handling needed for itemstacks.
@ -35,7 +36,7 @@ trait ItemEnchantmentHandlingTrait{
protected $enchantments = [];
public function hasEnchantments() : bool{
return !empty($this->enchantments);
return count($this->enchantments) > 0;
}
public function hasEnchantment(Enchantment $enchantment, int $level = -1) : bool{

View File

@ -682,7 +682,7 @@ class NetworkSession{
$lname = strtolower($command->getName());
$aliases = $command->getAliases();
$aliasObj = null;
if(!empty($aliases)){
if(count($aliases) > 0){
if(!in_array($lname, $aliases, true)){
//work around a client bug which makes the original name not show when aliases are used
$aliases[] = $lname;

View File

@ -35,7 +35,7 @@ class MismatchTransactionData extends TransactionData{
}
protected function decodeData(NetworkBinaryStream $stream) : void{
if(!empty($this->actions)){
if(count($this->actions) > 0){
throw new BadPacketException("Mismatch transaction type should not have any actions associated with it, but got " . count($this->actions));
}
}

View File

@ -23,6 +23,7 @@ declare(strict_types=1);
namespace pocketmine\permission;
use function count;
use function is_array;
use function is_bool;
use function ksort;
@ -151,7 +152,7 @@ class PermissionParser{
}
$children[$name] = self::emitPermission($child);
}
if(!empty($children)){
if(count($children) > 0){
ksort($children);
$result["children"] = $children;
}

View File

@ -901,7 +901,7 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener,
}
$this->loadQueue = $newOrder;
if(!empty($this->loadQueue) or !empty($unloadChunks)){
if(count($this->loadQueue) > 0 or count($unloadChunks) > 0){
$this->networkSession->syncViewAreaCenterPoint($this->location, $this->viewDistance);
}

View File

@ -243,7 +243,7 @@ class PluginManager{
continue;
}
$ambiguousVersions = ApiVersion::checkAmbiguousVersions($description->getCompatibleApis());
if(!empty($ambiguousVersions)){
if(count($ambiguousVersions) > 0){
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [
$name,
$this->server->getLanguage()->translateString("pocketmine.plugin.ambiguousMinAPI", [implode(", ", $ambiguousVersions)])

View File

@ -88,7 +88,7 @@ trait RegistryTrait{
* @return object
*/
public static function __callStatic($name, $arguments){
if(!empty($arguments)){
if(count($arguments) > 0){
throw new \ArgumentCountError("Expected exactly 0 arguments, " . count($arguments) . " passed");
}
try{

View File

@ -608,7 +608,7 @@ class World implements ChunkManager{
$hash = World::chunkHash($chunkX, $chunkZ);
if(isset($this->chunkListeners[$hash])){
unset($this->chunkListeners[$hash][spl_object_id($listener)]);
if(empty($this->chunkListeners[$hash])){
if(count($this->chunkListeners[$hash]) === 0){
unset($this->chunkListeners[$hash]);
}
}
@ -622,7 +622,7 @@ class World implements ChunkManager{
foreach($this->chunkListeners as $hash => $listeners){
if(isset($listeners[$id])){
unset($this->chunkListeners[$hash][$id]);
if(empty($this->chunkListeners[$hash])){
if(count($this->chunkListeners[$hash]) === 0){
unset($this->chunkListeners[$hash]);
}
}
@ -646,7 +646,7 @@ class World implements ChunkManager{
public function sendTime(Player ...$targets) : void{
$pk = SetTimePacket::create($this->time);
if(empty($targets)){
if(count($targets) === 0){
$this->broadcastGlobalPacket($pk);
}else{
$this->server->broadcastPackets($targets, [$pk]);
@ -2370,7 +2370,7 @@ class World implements ChunkManager{
*/
public function sendDifficulty(Player ...$targets) : void{
$pk = SetDifficultyPacket::create($this->getDifficulty());
if(empty($targets)){
if(count($targets) === 0){
$this->broadcastGlobalPacket($pk);
}else{
$this->server->broadcastPackets($targets, [$pk]);

View File

@ -182,7 +182,7 @@ class WorldManager{
if(count($providers) !== 1){
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.level.loadError", [
$name,
empty($providers) ?
count($providers) === 0 ?
$this->server->getLanguage()->translateString("pocketmine.level.unknownFormat") :
$this->server->getLanguage()->translateString("pocketmine.level.ambiguousFormat", [implode(", ", array_keys($providers))])
]));
@ -302,7 +302,7 @@ class WorldManager{
}
$path = $this->server->getDataPath() . "worlds/" . $name . "/";
if(!($this->getWorldByName($name) instanceof World)){
return !empty(WorldProviderManager::getMatchingProviders($path));
return count(WorldProviderManager::getMatchingProviders($path)) > 0;
}
return true;

View File

@ -548,7 +548,7 @@ class Chunk{
}
public function isDirty() : bool{
return $this->dirtyFlags !== 0 or !empty($this->tiles) or !empty($this->getSavableEntities());
return $this->dirtyFlags !== 0 or count($this->tiles) > 0 or count($this->getSavableEntities()) > 0;
}
public function getDirtyFlag(int $flag) : bool{

View File

@ -24,6 +24,7 @@ declare(strict_types=1);
namespace pocketmine\world\format;
use function array_values;
use function count;
class SubChunk implements SubChunkInterface{
/** @var int */
@ -55,18 +56,18 @@ class SubChunk implements SubChunkInterface{
}
public function isEmptyFast() : bool{
return empty($this->blockLayers);
return count($this->blockLayers) === 0;
}
public function getFullBlock(int $x, int $y, int $z) : int{
if(empty($this->blockLayers)){
if(count($this->blockLayers) === 0){
return $this->defaultBlock;
}
return $this->blockLayers[0]->get($x, $y, $z);
}
public function setFullBlock(int $x, int $y, int $z, int $block) : void{
if(empty($this->blockLayers)){
if(count($this->blockLayers) === 0){
$this->blockLayers[] = new PalettedBlockArray($this->defaultBlock);
}
$this->blockLayers[0]->set($x, $y, $z, $block);
@ -80,7 +81,7 @@ class SubChunk implements SubChunkInterface{
}
public function getHighestBlockAt(int $x, int $z) : int{
if(empty($this->blockLayers)){
if(count($this->blockLayers) === 0){
return -1;
}
for($y = 15; $y >= 0; --$y){

View File

@ -482,7 +482,7 @@ class LevelDB extends BaseWorldProvider implements WritableWorldProvider{
* @param CompoundTag[] $targets
*/
private function writeTags(array $targets, string $index, \LevelDBWriteBatch $write) : void{
if(!empty($targets)){
if(count($targets) > 0){
$nbt = new LittleEndianNbtSerializer();
$write->put($index, $nbt->writeMultiple(array_map(function(CompoundTag $tag) : TreeRoot{ return new TreeRoot($tag); }, $targets)));
}else{