优化代码

main
gzydong 2021-08-10 21:35:41 +08:00
parent c1465d9963
commit c8a67907bc
4 changed files with 13 additions and 10 deletions

View File

@ -129,7 +129,7 @@ class ContactsController extends CController
]); ]);
$user_id = $this->uid(); $user_id = $this->uid();
$isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']); $isTrue = $this->service->editRemark($user_id, intval($params['friend_id']), $params['remarks']);
if (!$isTrue) { if (!$isTrue) {
return $this->response->fail('备注修改失败!'); return $this->response->fail('备注修改失败!');
} }

View File

@ -17,9 +17,9 @@ trait PagingTrait
* @param int $page_size 分页大小 * @param int $page_size 分页大小
* @return int 分页总数 * @return int 分页总数
*/ */
protected function getPagingTotal(int $total, int $page_size) protected function getPagingTotal(int $total, int $page_size): int
{ {
return ($total === 0) ? 0 : (int)ceil((int)$total / (int)$page_size); return ($total === 0) ? 0 : (int)ceil($total / $page_size);
} }
/** /**
@ -32,7 +32,7 @@ trait PagingTrait
* @param array $params 额外参数 * @param array $params 额外参数
* @return array * @return array
*/ */
protected function getPagingRows(array $rows, int $total, int $page, int $page_size, array $params = []) protected function getPagingRows(array $rows, int $total, int $page, int $page_size, array $params = []): array
{ {
return array_merge([ return array_merge([
'rows' => $rows, 'rows' => $rows,

View File

@ -1,4 +1,5 @@
<?php <?php
declare(strict_types=1);
namespace App\Traits; namespace App\Traits;

View File

@ -15,13 +15,15 @@ use Swoole\Websocket\Frame;
use Swoole\WebSocket\Server as WebSocketServer; use Swoole\WebSocket\Server as WebSocketServer;
use Hyperf\Utils\Str; use Hyperf\Utils\Str;
use Hyperf\Redis\Redis; use Hyperf\Redis\Redis;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
/** /**
* 容器实例 * 容器实例
* *
* @return \Psr\Container\ContainerInterface * @return ContainerInterface
*/ */
function di() function di(): ContainerInterface
{ {
return ApplicationContext::getContainer(); return ApplicationContext::getContainer();
} }
@ -98,9 +100,9 @@ function stdout_log()
* 文件日志 * 文件日志
* *
* @param string $name * @param string $name
* @return \Psr\Log\LoggerInterface * @return LoggerInterface
*/ */
function logger(string $name = 'APP') function logger(string $name = 'APP'): LoggerInterface
{ {
return di()->get(LoggerFactory::class)->get($name); return di()->get(LoggerFactory::class)->get($name);
} }
@ -190,7 +192,7 @@ function get_media_url(string $path)
* @param array $filesize 图片文件大小信息 * @param array $filesize 图片文件大小信息
* @return string * @return string
*/ */
function create_image_name(string $ext, array $filesize) function create_image_name(string $ext, array $filesize): string
{ {
return uniqid() . Str::random() . '_' . $filesize[0] . 'x' . $filesize[1] . '.' . $ext; return uniqid() . Str::random() . '_' . $filesize[0] . 'x' . $filesize[1] . '.' . $ext;
} }
@ -277,7 +279,7 @@ function push_redis_subscribe(string $chan, $message)
* @param string $ext 文件后缀名 * @param string $ext 文件后缀名
* @return string * @return string
*/ */
function create_random_filename(string $ext) function create_random_filename(string $ext): string
{ {
$ext = $ext ? '.' . $ext : ''; $ext = $ext ? '.' . $ext : '';
return Str::random(10) . uniqid() . $ext; return Str::random(10) . uniqid() . $ext;