Add tools/ to PHPStan analysis

This commit is contained in:
Dylan K. Taylor 2021-08-29 23:31:24 +01:00
parent 6bbc0aae7d
commit ee8b854f30
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D
3 changed files with 15 additions and 7 deletions

View File

@ -27,6 +27,7 @@ parameters:
- tests/phpstan/bootstrap.php
scanDirectories:
- tests/plugins/TesterPlugin
- tools
scanFiles:
- src/PocketMine.php
- build/make-release.php
@ -39,6 +40,7 @@ parameters:
- build/server-phar.php
- tests/phpunit
- tests/plugins/TesterPlugin
- tools
dynamicConstantNames:
- pocketmine\VersionInfo::IS_DEVELOPMENT_BUILD
- pocketmine\DEBUG

View File

@ -59,7 +59,11 @@ const SUPPORTED_EXTENSIONS = [
* @phpstan-param array<string, int> $files
*/
function find_regions_recursive(string $dir, array &$files) : void{
foreach(scandir($dir, SCANDIR_SORT_NONE) as $file){
$dirFiles = scandir($dir, SCANDIR_SORT_NONE);
if($dirFiles === false){
return;
}
foreach($dirFiles as $file){
if($file === "." or $file === ".."){
continue;
}

View File

@ -39,11 +39,13 @@ $usageMessage = "Options:\n";
foreach($requiredOpts as $_opt => $_desc){
$usageMessage .= "\t--$_opt : $_desc\n";
}
$args = getopt("", array_map(function(string $str){ return "$str:"; }, array_keys($requiredOpts)));
$plainArgs = getopt("", array_map(function(string $str){ return "$str:"; }, array_keys($requiredOpts)));
$args = [];
foreach($requiredOpts as $opt => $desc){
if(!isset($args[$opt])){
if(!isset($plainArgs[$opt]) || !is_string($plainArgs[$opt])){
die($usageMessage);
}
$args[$opt] = $plainArgs[$opt];
}
if(!array_key_exists($args["format"], $writableFormats)){
die($usageMessage);
@ -53,9 +55,9 @@ $inputPath = realpath($args["world"]);
if($inputPath === false){
die("Cannot find input world at location: " . $args["world"]);
}
$backupPath = $args["backup"];
if((!@mkdir($backupPath, 0777, true) and !is_dir($backupPath)) or !is_writable($backupPath)){
die("Backup file path " . $backupPath . " is not writable (permission error or doesn't exist), aborting");
$backupPath = realpath($args["backup"]);
if($backupPath === false || (!@mkdir($backupPath, 0777, true) and !is_dir($backupPath)) or !is_writable($backupPath)){
die("Backup file path " . $args["backup"] . " is not writable (permission error or doesn't exist), aborting");
}
$oldProviderClasses = $providerManager->getMatchingProviders($inputPath);
@ -68,5 +70,5 @@ if(count($oldProviderClasses) > 1){
$oldProviderClass = array_shift($oldProviderClasses);
$oldProvider = $oldProviderClass->fromPath($inputPath);
$converter = new FormatConverter($oldProvider, $writableFormats[$args["format"]], realpath($backupPath), GlobalLogger::get());
$converter = new FormatConverter($oldProvider, $writableFormats[$args["format"]], $backupPath, GlobalLogger::get());
$converter->execute();