From 4d874e7e786c83f585e7bbdfb023671dac3be2ae Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 13 Jul 2017 16:45:24 +0100 Subject: [PATCH] static analysis --- src/pocketmine/command/FormattedCommandAlias.php | 2 +- src/pocketmine/entity/Attribute.php | 2 ++ src/pocketmine/lang/BaseLang.php | 2 +- src/pocketmine/level/format/io/region/McRegion.php | 2 +- src/pocketmine/resourcepacks/ResourcePackManager.php | 2 +- src/pocketmine/utils/Utils.php | 3 +-- 6 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/pocketmine/command/FormattedCommandAlias.php b/src/pocketmine/command/FormattedCommandAlias.php index 1ddde2c42..7cac99afc 100644 --- a/src/pocketmine/command/FormattedCommandAlias.php +++ b/src/pocketmine/command/FormattedCommandAlias.php @@ -125,7 +125,7 @@ class FormattedCommandAlias extends Command{ $replacement = ""; if($rest and $position < count($args)){ - for($i = $position; $i < count($args); ++$i){ + for($i = $position, $c = count($args); $i < $c; ++$i){ if($i !== $position){ $replacement .= " "; } diff --git a/src/pocketmine/entity/Attribute.php b/src/pocketmine/entity/Attribute.php index bd4310d0a..bc8988376 100644 --- a/src/pocketmine/entity/Attribute.php +++ b/src/pocketmine/entity/Attribute.php @@ -76,6 +76,8 @@ class Attribute{ * @param bool $shouldSend * * @return Attribute + * + * @throws \InvalidArgumentException */ public static function addAttribute($id, $name, $minValue, $maxValue, $defaultValue, $shouldSend = true){ if($minValue > $maxValue or $defaultValue > $maxValue or $defaultValue < $minValue){ diff --git a/src/pocketmine/lang/BaseLang.php b/src/pocketmine/lang/BaseLang.php index 58c3f8f22..60b38fb31 100644 --- a/src/pocketmine/lang/BaseLang.php +++ b/src/pocketmine/lang/BaseLang.php @@ -37,7 +37,7 @@ class BaseLang{ } if(is_dir($path)){ - $allFiles = scandir($path); + $allFiles = scandir($path, SCANDIR_SORT_NONE); if($allFiles !== false){ $files = array_filter($allFiles, function($filename){ diff --git a/src/pocketmine/level/format/io/region/McRegion.php b/src/pocketmine/level/format/io/region/McRegion.php index 8ffc81c2b..88ea43e54 100644 --- a/src/pocketmine/level/format/io/region/McRegion.php +++ b/src/pocketmine/level/format/io/region/McRegion.php @@ -223,7 +223,7 @@ class McRegion extends BaseLevelProvider{ $isValid = (file_exists($path . "/level.dat") and is_dir($path . "/region/")); if($isValid){ - $files = array_filter(scandir($path . "/region/"), function($file){ + $files = array_filter(scandir($path . "/region/", SCANDIR_SORT_NONE), function($file){ return substr($file, strrpos($file, ".") + 1, 2) === "mc"; //region file }); diff --git a/src/pocketmine/resourcepacks/ResourcePackManager.php b/src/pocketmine/resourcepacks/ResourcePackManager.php index 620b5af47..a5039269c 100644 --- a/src/pocketmine/resourcepacks/ResourcePackManager.php +++ b/src/pocketmine/resourcepacks/ResourcePackManager.php @@ -64,7 +64,7 @@ class ResourcePackManager{ } if(!file_exists($this->path . "resource_packs.yml")){ - file_put_contents($this->path . "resource_packs.yml", file_get_contents($this->server->getFilePath() . "src/pocketmine/resources/resource_packs.yml")); + copy($this->server->getFilePath() . "src/pocketmine/resources/resource_packs.yml", $this->path . "resource_packs.yml"); } $this->resourcePacksConfig = new Config($this->path . "resource_packs.yml", Config::YAML, []); diff --git a/src/pocketmine/utils/Utils.php b/src/pocketmine/utils/Utils.php index d128f5168..45794b12a 100644 --- a/src/pocketmine/utils/Utils.php +++ b/src/pocketmine/utils/Utils.php @@ -305,7 +305,6 @@ class Utils{ break; case "bsd": case "mac": - $processors = (int) `sysctl -n hw.ncpu`; $processors = (int) `sysctl -n hw.ncpu`; break; case "win": @@ -477,7 +476,7 @@ class Utils{ public static function javaStringHash($string){ $hash = 0; - for($i = 0; $i < strlen($string); $i++){ + for($i = 0, $len = strlen($string); $i < $len; $i++){ $ord = ord($string{$i}); if($ord & 0x80){ $ord -= 0x100;