Explorar o código

优化:改为箭头函数写法

萤火科技 hai 1 ano
pai
achega
876611b1e3

+ 1 - 3
app/api/model/UserAddress.php

@@ -95,9 +95,7 @@ class UserAddress extends UserAddressModel
         if (count($data['region']) != 3) {
             throwError('省市区数据不正确');
         }
-        return array_map(function ($item) {
-            return $item['value'];
-        }, $data['region']);
+        return \array_map(fn($item) => $item['value'], $data['region']);
     }
 
     /**

+ 3 - 4
app/common/library/express/provider/driver/Aliyun.php

@@ -41,7 +41,7 @@ class Aliyun extends Driver
         $appCode = $this->options['appCode'];
         $headers = ["Authorization: APPCODE " . $appCode];
         // 查询顺丰和中通时 物流单号需要加上手机尾号
-        if ( in_array($code, ['SF', 'ZTO'])) {
+        if (\in_array($code, ['SF', 'ZTO'])) {
             $lastPhoneNumber = \mb_substr($extra['phone'], -4);
             $expressNo = "{$expressNo}:$lastPhoneNumber";
         }
@@ -67,9 +67,8 @@ class Aliyun extends Driver
      */
     private function formatTraces(array $source): array
     {
-        return array_map(function ($item) {
-            return ['time' => $item['AcceptTime'], 'context' => $item['AcceptStation']];
-        }, array_reverse($source));
+        return \array_map(fn($item) => ['time' => $item['AcceptTime'], 'context' => $item['AcceptStation']]
+            , array_reverse($source));
     }
 
     /**

+ 2 - 4
app/common/library/express/provider/driver/Kd100.php

@@ -45,7 +45,7 @@ class Kd100 extends Driver
                 'com' => $code,
                 'num' => $expressNo,
                 // 顺丰参数 (需传参收、寄件人的电话号码)
-                'phone' =>  $code === 'shunfeng' ? $extra['phone']: ''
+                'phone' => $code === 'shunfeng' ? $extra['phone'] : ''
             ])
         ];
         $param['sign'] = strtoupper(md5($param['param'] . $this->options['key'] . $param['customer']));
@@ -69,9 +69,7 @@ class Kd100 extends Driver
      */
     private function formatTraces(array $source): array
     {
-        return array_map(function ($item) {
-            return ['time' => $item['ftime'], 'context' => $item['context']];
-        }, $source);
+        return \array_map(fn($item) => ['time' => $item['ftime'], 'context' => $item['context']], $source);
     }
 
     /**

+ 3 - 3
app/common/library/storage/engine/Basics.php

@@ -200,9 +200,9 @@ abstract class Basics
      */
     private function hashName(): string
     {
-        return $this->file->hashName(function () {
-            return date('Ymd') . DIRECTORY_SEPARATOR . md5(uniqid((string)mt_rand(), true));
-        });
+        return $this->file->hashName(
+            fn() => \date('Ymd') . DIRECTORY_SEPARATOR . \md5(\uniqid((string)\mt_rand(), true))
+        );
     }
 
     /**

+ 4 - 6
app/common/model/Comment.php

@@ -84,12 +84,10 @@ class Comment extends BaseModel
      */
     protected function addCommentImages(array $images): bool
     {
-        $data = array_map(function ($imageId) {
-            return [
-                'image_id' => $imageId,
-                'store_id' => self::$storeId
-            ];
-        }, $images);
+        $data = \array_map(fn($imageId) => [
+            'image_id' => $imageId,
+            'store_id' => self::$storeId
+        ], $images);
         return $this->image()->saveAll($data) !== false;
     }
 }

+ 7 - 6
app/store/service/store/Role.php

@@ -94,6 +94,11 @@ class Role extends BaseService
         return $actionEntitySet;
     }
 
+    /**
+     * 整理菜单列表的actions
+     * @param $menuList
+     * @return array
+     */
     private static function filterChildrenAction($menuList): array
     {
         $list = [];
@@ -102,11 +107,7 @@ class Role extends BaseService
                 continue;
             }
             if (!empty($item['children'])) {
-                // 整理actions
-                $item['actions'] = array_filter($item['children'], function ($val) {
-                    return $val['type'] == MenuTypeEnum::ACTION;
-                });
-                // 整理children
+                $item['actions'] = \array_filter($item['children'], fn($val) => $val['type'] == MenuTypeEnum::ACTION);
                 $item['children'] = static::filterChildrenAction($item['children']);
             }
             $list[] = $item;
@@ -130,7 +131,7 @@ class Role extends BaseService
         $menuIds = RoleMenuModel::getMenuIds($roleIds);
         // 获取指定角色ID的菜单列表
         $menuList = MenuModel::getListByIds($menuIds);
-        //  整理菜单列表的actions
+        // 整理菜单列表的actions
         return static::filterChildrenAction($menuList);
     }
 }

+ 1 - 1
cores/BaseController.php

@@ -51,7 +51,7 @@ abstract class BaseController
      * BaseController constructor.
      * @param App $app
      */
-    public function __construct(App $app)
+    public final function __construct(App $app)
     {
         $this->app = $app;
         $this->request = $this->app->request;