Copilot fixes

This commit is contained in:
slawkens
2026-02-15 01:57:26 +01:00
parent 4bc3923996
commit ad1d069b1f
8 changed files with 38 additions and 15 deletions

View File

@@ -16,7 +16,13 @@ use MyAAC\Models\Spell;
class Items class Items
{ {
public static $items; public static array $items;
private static string $error = '';
public static function getError(): string {
return self::$error;
}
public static function load(): bool { public static function load(): bool {
$file_path = config('data_path') . 'items/items.toml'; $file_path = config('data_path') . 'items/items.toml';
@@ -27,10 +33,14 @@ class Items
$items = new Server\XML\Items(); $items = new Server\XML\Items();
} }
else { else {
self::$error = 'Cannot load items.xml or items.toml file. Files not found.';
return false; return false;
} }
$items->load(); if (!$items->load()) {
self::$error = $items->getError();
return false;
}
return true; return true;
} }

View File

@@ -6,7 +6,7 @@ use MyAAC\Cache\Cache;
class Groups class Groups
{ {
private static array $groups; private static array $groups = [];
public function __construct() { public function __construct() {
self::$groups = Cache::remember('groups', 10 * 60, function () { self::$groups = Cache::remember('groups', 10 * 60, function () {

View File

@@ -6,7 +6,7 @@ use Devium\Toml\Toml;
class Groups class Groups
{ {
private array $groups; private array $groups = [];
public function load(): void public function load(): void
{ {
@@ -14,7 +14,7 @@ class Groups
if(!@file_exists($file)) { if(!@file_exists($file)) {
error('Error: Cannot load groups.toml. More info in system/logs/error.log file.'); error('Error: Cannot load groups.toml. More info in system/logs/error.log file.');
log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.toml (' . $file . '). It doesnt exist.'); log_append('error.log', "[OTS_Groups_List.php] Fatal error: Cannot load groups.toml ($file). It doesn't exist.");
return; return;
} }

View File

@@ -33,7 +33,20 @@ class Items
return !in_array($key, ['id', 'article', 'name', 'plural']); return !in_array($key, ['id', 'article', 'name', 'plural']);
}, ARRAY_FILTER_USE_KEY); }, ARRAY_FILTER_USE_KEY);
$items[$item['id']] = ['article' => $item['article'], 'name' => $item['name'], 'plural' => $item['plural'] ?? '', 'attributes' => $attributes]; $id = $item['id'] ?? null;
if ($id === null) {
continue;
}
$article = $item['article'] ?? '';
$name = $item['name'] ?? '';
$plural = $item['plural'] ?? '';
$items[$id] = [
'article' => $article,
'name' => $name,
'plural' => $plural,
'attributes' => $attributes,
];
} }
$cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/'); $cache_php = new CachePHP(config('cache_prefix'), CACHE . 'persistent/');

View File

@@ -6,14 +6,14 @@ use Devium\Toml\Toml;
class Vocations class Vocations
{ {
private array $vocations; private array $vocations = [];
private array $vocationsFrom; private array $vocationsFrom = [];
public function load(): void public function load(): void
{ {
$tomlVocations = glob(config('data_path') . 'vocations/*.toml'); $tomlVocations = glob(config('data_path') . 'vocations/*.toml');
if (count($tomlVocations) <= 0) { if (count($tomlVocations) <= 0) {
throw new \RuntimeException('ERROR: Cannot load any <i>.toml</i> vocation in the data/vocations folder.'); throw new \RuntimeException('ERROR: Cannot load any .toml vocation from the data/vocations folder.');
} }
foreach ($tomlVocations as $file) { foreach ($tomlVocations as $file) {

View File

@@ -6,8 +6,8 @@ use MyAAC\Cache\Cache;
class Vocations class Vocations
{ {
private static array $vocations; private static array $vocations = [];
private static array $vocationsFrom; private static array $vocationsFrom = [];
public function __construct() { public function __construct() {
$cached = Cache::remember('vocations', 10 * 60, function () { $cached = Cache::remember('vocations', 10 * 60, function () {

View File

@@ -4,7 +4,7 @@ namespace MyAAC\Server\XML;
class Groups class Groups
{ {
private array $groups; private array $groups = [];
public function load(): void public function load(): void
{ {
@@ -12,7 +12,7 @@ class Groups
if(!@file_exists($file)) { if(!@file_exists($file)) {
error('Error: Cannot load groups.xml. More info in system/logs/error.log file.'); error('Error: Cannot load groups.xml. More info in system/logs/error.log file.');
log_append('error.log', '[OTS_Groups_List.php] Fatal error: Cannot load groups.xml (' . $file . '). It doesnt exist.'); log_append('error.log', "[OTS_Groups_List.php] Fatal error: Cannot load groups.xml ($file). It doesn't exist.");
return; return;
} }

View File

@@ -4,8 +4,8 @@ namespace MyAAC\Server\XML;
class Vocations class Vocations
{ {
private array $vocations; private array $vocations = [];
private array $vocationsFrom; private array $vocationsFrom = [];
public function load(): void public function load(): void
{ {