mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-14 11:20:53 +08:00
fix: resolve PHPStan static analysis warnings
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user