fix: resolve PHPStan static analysis warnings

This commit is contained in:
xboard
2025-05-07 19:48:19 +08:00
parent db235c10e8
commit 97e7ffccae
86 changed files with 2335 additions and 1206 deletions

View File

@@ -15,14 +15,18 @@ class ServerService
* 获取所有服务器列表
* @return Collection
*/
public static function getAllServers()
public static function getAllServers(): Collection
{
return Server::orderBy('sort', 'ASC')
->get()
->transform(function (Server $server) {
$server->loadServerStatus();
return $server;
});
$query = Server::orderBy('sort', 'ASC');
return $query->get()->append([
'last_check_at',
'last_push_at',
'online',
'is_online',
'available_status',
'cache_key'
]);
}
/**
@@ -32,28 +36,25 @@ class ServerService
*/
public static function getAvailableServers(User $user): array
{
return Server::whereJsonContains('group_ids', (string) $user->group_id)
$servers = Server::whereJsonContains('group_ids', (string) $user->group_id)
->where('show', true)
->orderBy('sort', 'ASC')
->get()
->transform(function (Server $server) use ($user) {
$server->loadParentCreatedAt();
$server->handlePortAllocation();
$server->loadServerStatus();
if ($server->type === 'shadowsocks') {
$server->server_key = Helper::getServerKey($server->created_at, 16);
}
$server->generateShadowsocksPassword($user);
->append(['last_check_at', 'last_push_at', 'online', 'is_online', 'available_status', 'cache_key', 'server_key']);
return $server;
})
->toArray();
$servers = collect($servers)->map(function ($server) use ($user) {
// 判断动态端口
if (str_contains($server->port, '-')) {
$server->port = (string) Helper::randomPort($server->port);
$server->ports = $server->port;
}
$server->password = $server->generateShadowsocksPassword($user);
return $server;
})->toArray();
return $servers;
}
/**
* 加
*/
/**
* 根据权限组获取可用的用户列表
* @param array $groupIds