From fdaf86ce925543700777bf92b071bc4095c242a6 Mon Sep 17 00:00:00 2001 From: Karson Date: Tue, 6 Jun 2023 18:22:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/controller/Backend.php | 12 ++++++------ application/common/library/Auth.php | 2 +- application/common/library/Email.php | 6 +++--- application/common/library/Ems.php | 12 +++++------- application/common/library/Log.php | 10 ++++------ application/common/library/Menu.php | 8 ++++---- application/common/library/Sms.php | 10 ++++------ application/common/library/Token.php | 2 +- application/common/library/Upload.php | 14 +++++++------- application/common/model/Area.php | 4 ++-- application/common/model/Category.php | 2 +- application/common/model/Config.php | 6 +++--- application/common/model/Ems.php | 3 +-- application/common/model/MoneyLog.php | 2 +- application/common/model/ScoreLog.php | 2 +- application/common/model/Sms.php | 3 +-- extend/fast/Http.php | 2 +- extend/fast/Tree.php | 4 ++-- 18 files changed, 48 insertions(+), 56 deletions(-) diff --git a/application/common/controller/Backend.php b/application/common/controller/Backend.php index b70eede8..51cef5fd 100644 --- a/application/common/controller/Backend.php +++ b/application/common/controller/Backend.php @@ -312,12 +312,12 @@ class Backend extends Controller if (!preg_match('/^[a-zA-Z0-9_\-\.]+$/', $k)) { continue; } - $sym = isset($op[$k]) ? $op[$k] : '='; + $sym = $op[$k] ?? '='; if (stripos($k, ".") === false) { $k = $aliasName . $k; } $v = !is_array($v) ? trim($v) : $v; - $sym = strtoupper(isset($op[$k]) ? $op[$k] : $sym); + $sym = strtoupper($op[$k] ?? $sym); //null和空字符串特殊处理 if (!is_array($v)) { if (in_array(strtoupper($v), ['NULL', 'NOT NULL'])) { @@ -367,8 +367,8 @@ class Backend extends Controller case 'NOT BETWEEN': $arr = array_slice(explode(',', $v), 0, 2); if (stripos($v, ',') === false || !array_filter($arr, function ($v) { - return $v != '' && $v !== false && $v !== null; - })) { + return $v != '' && $v !== false && $v !== null; + })) { continue 2; } //当出现一边为空时改变操作符 @@ -568,8 +568,8 @@ class Backend extends Controller unset($item['password'], $item['salt']); if ($this->selectpageFields == '*') { $result = [ - $primarykey => isset($item[$primarykey]) ? $item[$primarykey] : '', - $field => isset($item[$field]) ? $item[$field] : '', + $primarykey => $item[$primarykey] ?? '', + $field => $item[$field] ?? '', ]; } else { $result = array_intersect_key(($item instanceof Model ? $item->toArray() : (array)$item), array_flip($fields)); diff --git a/application/common/library/Auth.php b/application/common/library/Auth.php index 38a19a06..5a15b051 100644 --- a/application/common/library/Auth.php +++ b/application/common/library/Auth.php @@ -547,7 +547,7 @@ class Auth } } foreach ($datalist as $k => &$v) { - $v[$renderkey] = isset($list[$v[$fieldkey]]) ? $list[$v[$fieldkey]] : null; + $v[$renderkey] = $list[$v[$fieldkey]] ?? null; } unset($v); return $datalist; diff --git a/application/common/library/Email.php b/application/common/library/Email.php index f51b0689..aa3796c5 100644 --- a/application/common/library/Email.php +++ b/application/common/library/Email.php @@ -60,7 +60,7 @@ class Email } $this->options = array_merge($this->options, $options); $secureArr = [0 => '', 1 => 'tls', 2 => 'ssl']; - $secure = isset($secureArr[$this->options['mail_verify_type']]) ? $secureArr[$this->options['mail_verify_type']] : ''; + $secure = $secureArr[$this->options['mail_verify_type']] ?? ''; $logger = isset($this->options['debug']) && $this->options['debug'] ? new Log : null; $this->mail = new Mailer($logger); @@ -217,8 +217,8 @@ class Email $this->setError($e->getCode() . $e->getMessage()); } catch (CodeException $e) { preg_match_all("/Expected: (\d+)\, Got: (\d+)( \| (.*))?\$/i", $e->getMessage(), $matches); - $code = isset($matches[2][3]) ? $matches[2][3] : 0; - $message = isset($matches[2][0]) ? $matches[4][0] : $e->getMessage(); + $code = $matches[2][0] ?? 0; + $message = $matches[4][0] ?? $e->getMessage(); $message = mb_convert_encoding($message, 'UTF-8', 'GBK,GB2312,BIG5'); $this->setError($message); } catch (\Exception $e) { diff --git a/application/common/library/Ems.php b/application/common/library/Ems.php index 4e5212a3..c655cf17 100644 --- a/application/common/library/Ems.php +++ b/application/common/library/Ems.php @@ -28,16 +28,15 @@ class Ems * * @param int $email 邮箱 * @param string $event 事件 - * @return Ems + * @return Ems|null */ public static function get($email, $event = 'default') { - $ems = \app\common\model\Ems:: - where(['email' => $email, 'event' => $event]) + $ems = \app\common\model\Ems::where(['email' => $email, 'event' => $event]) ->order('id', 'DESC') ->find(); Hook::listen('ems_get', $ems, null, true); - return $ems ? $ems : null; + return $ems ?: null; } /** @@ -103,7 +102,7 @@ class Ems }); } $result = Hook::listen('ems_notice', $params, null, true); - return $result ? true : false; + return (bool)$result; } /** @@ -150,8 +149,7 @@ class Ems */ public static function flush($email, $event = 'default') { - \app\common\model\Ems:: - where(['email' => $email, 'event' => $event]) + \app\common\model\Ems::where(['email' => $email, 'event' => $event]) ->delete(); Hook::listen('ems_flush'); return true; diff --git a/application/common/library/Log.php b/application/common/library/Log.php index a9d891dc..d9aff8df 100644 --- a/application/common/library/Log.php +++ b/application/common/library/Log.php @@ -14,15 +14,13 @@ class Log extends AbstractLogger /** * Logs with an arbitrary level. * - * @param mixed $level - * @param string $message - * @param mixed[] $context + * @param mixed $level + * @param string $message + * @param array $context * * @return void - * - * @throws \Psr\Log\InvalidArgumentException */ - public function log($level, $message, array $context = array()) + public function log($level, $message, array $context = []) { \think\Log::write($message); } diff --git a/application/common/library/Menu.php b/application/common/library/Menu.php index 292b78ef..f694ce0d 100644 --- a/application/common/library/Menu.php +++ b/application/common/library/Menu.php @@ -100,7 +100,7 @@ class Menu if ($ids) { //旧版本的菜单需要做删除处理 $config = Service::config($name); - $menus = isset($config['menus']) ? $config['menus'] : []; + $menus = $config['menus'] ?? []; $where = ['id' => ['in', $ids]]; if ($menus) { //必须是旧版本中的菜单,可排除用户自主创建的菜单 @@ -184,10 +184,10 @@ class Menu } $allow = array_flip(['file', 'name', 'title', 'url', 'icon', 'condition', 'remark', 'ismenu', 'menutype', 'extend', 'weigh']); foreach ($newMenu as $k => $v) { - $hasChild = isset($v['sublist']) && $v['sublist'] ? true : false; + $hasChild = isset($v['sublist']) && $v['sublist']; $data = array_intersect_key($v, $allow); - $data['ismenu'] = isset($data['ismenu']) ? $data['ismenu'] : ($hasChild ? 1 : 0); - $data['icon'] = isset($data['icon']) ? $data['icon'] : ($hasChild ? 'fa fa-list' : 'fa fa-circle-o'); + $data['ismenu'] = $data['ismenu'] ?? ($hasChild ? 1 : 0); + $data['icon'] = $data['icon'] ?? ($hasChild ? 'fa fa-list' : 'fa fa-circle-o'); $data['pid'] = $pid; $data['status'] = 'normal'; if (!isset($oldMenu[$data['name']])) { diff --git a/application/common/library/Sms.php b/application/common/library/Sms.php index 2be8fa05..2bf2b4f2 100644 --- a/application/common/library/Sms.php +++ b/application/common/library/Sms.php @@ -32,12 +32,11 @@ class Sms */ public static function get($mobile, $event = 'default') { - $sms = \app\common\model\Sms:: - where(['mobile' => $mobile, 'event' => $event]) + $sms = \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) ->order('id', 'DESC') ->find(); Hook::listen('sms_get', $sms, null, true); - return $sms ? $sms : null; + return $sms ?: null; } /** @@ -78,7 +77,7 @@ class Sms 'template' => $template ]; $result = Hook::listen('sms_notice', $params, null, true); - return $result ? true : false; + return (bool)$result; } /** @@ -125,8 +124,7 @@ class Sms */ public static function flush($mobile, $event = 'default') { - \app\common\model\Sms:: - where(['mobile' => $mobile, 'event' => $event]) + \app\common\model\Sms::where(['mobile' => $mobile, 'event' => $event]) ->delete(); Hook::listen('sms_flush'); return true; diff --git a/application/common/library/Token.php b/application/common/library/Token.php index 3486c46a..dab87097 100644 --- a/application/common/library/Token.php +++ b/application/common/library/Token.php @@ -150,7 +150,7 @@ class Token /** * 清除Token * @access public - * @param int user_id 会员ID + * @param int $user_id 会员ID * @return boolean */ public static function clear($user_id = null) diff --git a/application/common/library/Upload.php b/application/common/library/Upload.php index 77db11bf..aaeada77 100644 --- a/application/common/library/Upload.php +++ b/application/common/library/Upload.php @@ -15,7 +15,6 @@ use think\Hook; */ class Upload { - protected $merging = false; protected $chunkDir = null; @@ -130,8 +129,8 @@ class Upload if (!$imgInfo || !isset($imgInfo[0]) || !isset($imgInfo[1])) { throw new UploadException(__('Uploaded file is not a valid image')); } - $this->fileInfo['imagewidth'] = isset($imgInfo[0]) ? $imgInfo[0] : 0; - $this->fileInfo['imageheight'] = isset($imgInfo[1]) ? $imgInfo[1] : 0; + $this->fileInfo['imagewidth'] = $imgInfo[0] ?? 0; + $this->fileInfo['imageheight'] = $imgInfo[1] ?? 0; return true; } else { return !$force; @@ -148,11 +147,13 @@ class Upload $size = $matches ? $matches[1] : $this->config['maxsize']; $type = $matches ? strtolower($matches[2]) : 'b'; $typeDict = ['b' => 0, 'k' => 1, 'kb' => 1, 'm' => 2, 'mb' => 2, 'gb' => 3, 'g' => 3]; - $size = (int)($size * pow(1024, isset($typeDict[$type]) ? $typeDict[$type] : 0)); + $size = (int)($size * pow(1024, $typeDict[$type] ?? 0)); if ($this->fileInfo['size'] > $size) { - throw new UploadException(__('File is too big (%sMiB), Max filesize: %sMiB.', + throw new UploadException(__( + 'File is too big (%sMiB), Max filesize: %sMiB.', round($this->fileInfo['size'] / pow(1024, 2), 2), - round($size / pow(1024, 2), 2))); + round($size / pow(1024, 2), 2) + )); } } @@ -316,7 +317,6 @@ class Upload */ public function chunk($chunkid, $chunkindex, $chunkcount, $chunkfilesize = null, $chunkfilename = null, $direct = false) { - if ($this->fileInfo['type'] != 'application/octet-stream') { throw new UploadException(__('Uploaded file format is limited')); } diff --git a/application/common/model/Area.php b/application/common/model/Area.php index 204ff682..cca388dc 100644 --- a/application/common/model/Area.php +++ b/application/common/model/Area.php @@ -22,8 +22,8 @@ class Area extends Model { $namearr = [1 => 'geo:province', 2 => 'geo:city', 3 => 'geo:district']; $rangearr = [1 => 15000, 2 => 1000, 3 => 200]; - $geoname = isset($namearr[$level]) ? $namearr[$level] : $namearr[3]; - $georange = isset($rangearr[$level]) ? $rangearr[$level] : $rangearr[3]; + $geoname = $namearr[$level] ?? $namearr[3]; + $georange = $rangearr[$level] ?? $rangearr[3]; // 读取范围内的ID $redis = Cache::store('redis')->handler(); $georadiuslist = []; diff --git a/application/common/model/Category.php b/application/common/model/Category.php index 4adfd5d4..d9c4f54b 100644 --- a/application/common/model/Category.php +++ b/application/common/model/Category.php @@ -50,7 +50,7 @@ class Category extends Model { $value = $value ? $value : $data['type']; $list = $this->getTypeList(); - return isset($list[$value]) ? $list[$value] : ''; + return $list[$value] ?? ''; } public function getFlagList() diff --git a/application/common/model/Config.php b/application/common/model/Config.php index aa7ee0be..51fcaf70 100644 --- a/application/common/model/Config.php +++ b/application/common/model/Config.php @@ -115,8 +115,8 @@ class Config extends Model $data = $result; } $fieldarr = $valuearr = []; - $field = isset($data['field']) ? $data['field'] : (isset($data['key']) ? $data['key'] : []); - $value = isset($data['value']) ? $data['value'] : []; + $field = $data['field'] ?? ($data['key'] ?? []); + $value = $data['value'] ?? []; foreach ($field as $m => $n) { if ($n != '') { $fieldarr[] = $field[$m]; @@ -219,7 +219,7 @@ class Config extends Model } file_put_contents( CONF_PATH . 'extra' . DS . 'site.php', - ' $childdata || !isset($value['@url']) ? "javascript:;" : $value['@url'], '@addtabs' => $childdata || !isset($value['@url']) ? "" : (stripos($value['@url'], "?") !== false ? "&" : "?") . "ref=addtabs", '@caret' => ($childdata && (!isset($value['@badge']) || !$value['@badge']) ? '' : ''), - '@badge' => isset($value['@badge']) ? $value['@badge'] : '', + '@badge' => $value['@badge'] ?? '', '@class' => ($selected ? ' active' : '') . ($disabled ? ' disabled' : '') . ($childdata ? ' treeview' . (config('fastadmin.show_submenu') ? ' treeview-open' : '') : ''), ); $str .= strtr($nstr, $value); @@ -422,7 +422,7 @@ class Tree { $arr = []; foreach ($data as $k => $v) { - $childlist = isset($v['childlist']) ? $v['childlist'] : []; + $childlist = $v['childlist'] ?? []; unset($v['childlist']); $v[$field] = $v['spacer'] . ' ' . $v[$field]; $v['haschild'] = $childlist ? 1 : 0;