[WIP] Refactoring

This commit is contained in:
slawkens
2026-02-26 16:45:58 +01:00
parent 058e80cfc6
commit f738448f2e
3 changed files with 26 additions and 29 deletions

View File

@@ -9,8 +9,12 @@ class ItemsParser
$ret = [];
$i = 0;
$handle = fopen($path, "r");
if ($handle) {
$handle = fopen($path, 'r');
if ($handle === false) {
throw new \RuntimeException('Failed to open items file: ' . $path);
}
$parse = '';
while (($line = fgets($handle)) !== false) {
@@ -25,17 +29,18 @@ class ItemsParser
// skip lines like this
// field = {type = "fire", initdamage = 20, ticks = 10000, count = 7, damage = 10}
// as it cannot be parsed by parse_ini_string
if (str_contains($line, 'field =')) {
if (str_starts_with(ltrim($line), 'field =')) {
continue;
}
$parse .= $line;
}
if ($parse !== '') {
$ret[] = parse_ini_string($parse);
}
fclose($handle);
}
return $ret;
}

View File

@@ -6,7 +6,7 @@ use MyAAC\Cache\PHP as CachePHP;
class Items
{
private string $error;
private string $error = '';
public function getError(): string {
return $this->error;

View File

@@ -40,12 +40,4 @@ class Vocations
public function getFrom(): array {
return $this->vocationsFrom;
}
public static function getBase($includingRook = true): array {
return \MyAAC\Server\Vocations::getBase($includingRook);
}
public static function getOriginal(int $id): ?int {
return \MyAAC\Server\Vocations::getOriginal($id);
}
}