Karson 1 рік тому
батько
коміт
fdaf86ce92

+ 6 - 6
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));

+ 1 - 1
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;

+ 3 - 3
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) {

+ 5 - 7
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;

+ 4 - 6
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);
     }

+ 4 - 4
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']])) {

+ 4 - 6
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;

+ 1 - 1
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)

+ 7 - 7
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'));
         }

+ 2 - 2
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 = [];

+ 1 - 1
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()

+ 3 - 3
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',
-            '<?php' . "\n\nreturn " . var_export_short($config) . ";\n"
+            '<?php' . "\n\nreturn " . var_export($config, true) . ";\n"
         );
         return true;
     }

+ 1 - 2
application/common/model/Ems.php

@@ -7,7 +7,7 @@ use think\Model;
 /**
  * 邮箱验证码
  */
-class Ems Extends Model
+class Ems extends Model
 {
 
     // 开启自动写入时间戳字段
@@ -18,5 +18,4 @@ class Ems Extends Model
     // 追加属性
     protected $append = [
     ];
-
 }

+ 1 - 1
application/common/model/MoneyLog.php

@@ -7,7 +7,7 @@ use think\Model;
 /**
  * 会员余额日志模型
  */
-class MoneyLog Extends Model
+class MoneyLog extends Model
 {
 
     // 表名

+ 1 - 1
application/common/model/ScoreLog.php

@@ -7,7 +7,7 @@ use think\Model;
 /**
  * 会员积分日志模型
  */
-class ScoreLog Extends Model
+class ScoreLog extends Model
 {
 
     // 表名

+ 1 - 2
application/common/model/Sms.php

@@ -7,7 +7,7 @@ use think\Model;
 /**
  * 短信验证码
  */
-class Sms Extends Model
+class Sms extends Model
 {
 
     // 开启自动写入时间戳字段
@@ -18,5 +18,4 @@ class Sms Extends Model
     // 追加属性
     protected $append = [
     ];
-
 }

+ 1 - 1
extend/fast/Http.php

@@ -133,7 +133,7 @@ class Http
         }
         $parts['query'] = isset($parts['query']) && $parts['query'] ? '?' . $parts['query'] : '';
         //发送socket请求,获得连接句柄
-        $fp = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : 80, $errno, $errstr, 3);
+        $fp = fsockopen($parts['host'], $parts['port'] ?? 80, $errno, $errstr, 3);
         if (!$fp) {
             return false;
         }

+ 2 - 2
extend/fast/Tree.php

@@ -325,7 +325,7 @@ class Tree
                     '@url'       => $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']) ? '<i class="fa fa-angle-left"></i>' : ''),
-                    '@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;