From d0656a99b9f53d2ec90704d82f2c625a089decb6 Mon Sep 17 00:00:00 2001 From: zds <49744633+zds-s@users.noreply.github.com> Date: Fri, 19 Apr 2024 17:23:40 +0800 Subject: [PATCH] Code style (#232) --- app/System/Service/SystemUserService.php | 4 +--- common/common.php | 15 +++++---------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/System/Service/SystemUserService.php b/app/System/Service/SystemUserService.php index 4ffcc33b..3d3dcd56 100644 --- a/app/System/Service/SystemUserService.php +++ b/app/System/Service/SystemUserService.php @@ -68,14 +68,12 @@ public function __construct( /** * 获取用户信息. - * @param int|null $userId - * @return array * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ public function getInfo(?int $userId = null): array { - if ($uid = ( is_null($userId) ? user()->getId() : $userId )) { + if ($uid = (is_null($userId) ? user()->getId() : $userId)) { return $this->getCacheInfo($uid); } throw new MineException(t('system.unable_get_userinfo'), 500); diff --git a/common/common.php b/common/common.php index ace21a9c..8f5a4475 100644 --- a/common/common.php +++ b/common/common.php @@ -10,6 +10,7 @@ * @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE */ use App\Setting\Service\SettingConfigService; +use App\System\Service\SystemUserService; use App\System\Vo\AmqpQueueVo; use App\System\Vo\QueueMessageVo; use Hyperf\Cache\Listener\DeleteListenerEvent; @@ -139,16 +140,13 @@ function is_in_container(): bool if (! function_exists('has_permission')) { /** - * 检查用户是否拥有某权限 - * @param string $code - * @param int|null $userId - * @return bool + * 检查用户是否拥有某权限. * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ function has_permission(string $code, ?int $userId = null): bool { - $codes = container()->get(\App\System\Service\SystemUserService::class)->getInfo($userId)['codes']; + $codes = container()->get(SystemUserService::class)->getInfo($userId)['codes']; if ($codes[0] === '*') { return true; } @@ -158,16 +156,13 @@ function has_permission(string $code, ?int $userId = null): bool if (! function_exists('has_role')) { /** - * 检查用户是否拥有某角色 - * @param string $code - * @param int|null $userId - * @return bool + * 检查用户是否拥有某角色. * @throws ContainerExceptionInterface * @throws NotFoundExceptionInterface */ function has_role(string $code, ?int $userId = null): bool { - $roles = container()->get(\App\System\Service\SystemUserService::class)->getInfo($userId)['roles']; + $roles = container()->get(SystemUserService::class)->getInfo($userId)['roles']; if ($roles === 'superAdmin') { return true; }