Explorar o código

Merge pull request #692 from jqhph/analysis-lKj9Lr

Apply fixes from StyleCI
Jiang Qinghua %!s(int64=5) %!d(string=hai) anos
pai
achega
566ecb2b94

+ 3 - 3
src/Actions/HasActionHandler.php

@@ -15,9 +15,9 @@ trait HasActionHandler
      * @var Response
      */
     protected $response;
-    
+
     private $confirmString;
-    
+
     private $paramString;
 
     /**
@@ -81,7 +81,7 @@ trait HasActionHandler
         if ($this->confirmString !== null) {
             return $this->confirmString;
         }
-        
+
         $confirm = $this->confirm();
 
         return $this->confirmString = ($confirm ? admin_javascript_json((array) $confirm) : 'false');

+ 0 - 1
src/Admin.php

@@ -21,7 +21,6 @@ use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Event;
-use Illuminate\Support\Facades\Route;
 use Illuminate\Support\Str;
 
 class Admin

+ 143 - 143
src/Extend/CanImportMenu.php

@@ -1,143 +1,143 @@
-<?php
-
-namespace Dcat\Admin\Extend;
-
-use Illuminate\Support\Arr;
-use Illuminate\Support\Facades\Validator;
-
-/**
- * @property \Symfony\Component\Console\Output\OutputInterface $output
- */
-trait CanImportMenu
-{
-    protected $menu = [];
-
-    protected $menuValidationRules = [
-        'parent' => 'nullable',
-        'title'  => 'required',
-        'uri'    => 'nullable',
-        'icon'   => 'nullable',
-    ];
-
-    /**
-     * 获取菜单节点.
-     *
-     * @return array
-     */
-    protected function menu()
-    {
-        return $this->menu;
-    }
-
-    /**
-     * 添加菜单
-     *
-     * @param array $menu
-     *
-     * @throws \Exception
-     */
-    protected function addMenu(array $menu = [])
-    {
-        $menu = $menu ?: $this->menu();
-
-        if (! Arr::isAssoc($menu)) {
-            foreach ($menu as $v) {
-                $this->addMenu($v);
-            }
-
-            return;
-        }
-
-        if (! $this->validateMenu($menu)) {
-            return;
-        }
-
-        if ($menuModel = $this->getMenuModel()) {
-            $lastOrder = $menuModel::max('order');
-
-            $menuModel::create([
-                'parent_id' => $this->getParentMenuId($menu['parent'] ?? 0),
-                'order'     => $lastOrder + 1,
-                'title'     => $menu['title'],
-                'icon'      => (string) ($menu['icon'] ?? ''),
-                'uri'       => (string) ($menu['uri'] ?? ''),
-                'extension' => $this->getName(),
-            ]);
-        }
-    }
-
-    /**
-     * 刷新菜单.
-     *
-     * @throws \Exception
-     */
-    protected function refreshMenu()
-    {
-        $this->flushMenu();
-
-        $this->addMenu();
-    }
-
-    /**
-     * 根据名称获取菜单ID.
-     *
-     * @param int|string $parent
-     *
-     * @return int
-     */
-    protected function getParentMenuId($parent)
-    {
-        if (is_numeric($parent)) {
-            return $parent;
-        }
-
-        $menuModel = $this->getMenuModel();
-
-        return $menuModel::query()
-            ->where('title', $parent)
-            ->where('extension', $this->getName())
-            ->value('id') ?: 0;
-    }
-
-    /**
-     * 删除菜单.
-     */
-    protected function flushMenu()
-    {
-        $menuModel = $this->getMenuModel();
-
-        if (! $menuModel) {
-            return;
-        }
-
-        $menuModel::query()
-            ->where('extension', $this->getName())
-            ->delete();
-    }
-
-    /**
-     * 验证菜单字段格式是否正确.
-     *
-     * @param array $menu
-     *
-     * @throws \Exception
-     *
-     * @return bool
-     */
-    public function validateMenu(array $menu)
-    {
-        /** @var \Illuminate\Validation\Validator $validator */
-        $validator = Validator::make($menu, $this->menuValidationRules);
-
-        if ($validator->passes()) {
-            return true;
-        }
-
-        return false;
-    }
-
-    protected function getMenuModel()
-    {
-        return config('admin.database.menu_model');
-    }
-}
+<?php
+
+namespace Dcat\Admin\Extend;
+
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\Validator;
+
+/**
+ * @property \Symfony\Component\Console\Output\OutputInterface $output
+ */
+trait CanImportMenu
+{
+    protected $menu = [];
+
+    protected $menuValidationRules = [
+        'parent' => 'nullable',
+        'title'  => 'required',
+        'uri'    => 'nullable',
+        'icon'   => 'nullable',
+    ];
+
+    /**
+     * 获取菜单节点.
+     *
+     * @return array
+     */
+    protected function menu()
+    {
+        return $this->menu;
+    }
+
+    /**
+     * 添加菜单.
+     *
+     * @param array $menu
+     *
+     * @throws \Exception
+     */
+    protected function addMenu(array $menu = [])
+    {
+        $menu = $menu ?: $this->menu();
+
+        if (! Arr::isAssoc($menu)) {
+            foreach ($menu as $v) {
+                $this->addMenu($v);
+            }
+
+            return;
+        }
+
+        if (! $this->validateMenu($menu)) {
+            return;
+        }
+
+        if ($menuModel = $this->getMenuModel()) {
+            $lastOrder = $menuModel::max('order');
+
+            $menuModel::create([
+                'parent_id' => $this->getParentMenuId($menu['parent'] ?? 0),
+                'order'     => $lastOrder + 1,
+                'title'     => $menu['title'],
+                'icon'      => (string) ($menu['icon'] ?? ''),
+                'uri'       => (string) ($menu['uri'] ?? ''),
+                'extension' => $this->getName(),
+            ]);
+        }
+    }
+
+    /**
+     * 刷新菜单.
+     *
+     * @throws \Exception
+     */
+    protected function refreshMenu()
+    {
+        $this->flushMenu();
+
+        $this->addMenu();
+    }
+
+    /**
+     * 根据名称获取菜单ID.
+     *
+     * @param int|string $parent
+     *
+     * @return int
+     */
+    protected function getParentMenuId($parent)
+    {
+        if (is_numeric($parent)) {
+            return $parent;
+        }
+
+        $menuModel = $this->getMenuModel();
+
+        return $menuModel::query()
+            ->where('title', $parent)
+            ->where('extension', $this->getName())
+            ->value('id') ?: 0;
+    }
+
+    /**
+     * 删除菜单.
+     */
+    protected function flushMenu()
+    {
+        $menuModel = $this->getMenuModel();
+
+        if (! $menuModel) {
+            return;
+        }
+
+        $menuModel::query()
+            ->where('extension', $this->getName())
+            ->delete();
+    }
+
+    /**
+     * 验证菜单字段格式是否正确.
+     *
+     * @param array $menu
+     *
+     * @throws \Exception
+     *
+     * @return bool
+     */
+    public function validateMenu(array $menu)
+    {
+        /** @var \Illuminate\Validation\Validator $validator */
+        $validator = Validator::make($menu, $this->menuValidationRules);
+
+        if ($validator->passes()) {
+            return true;
+        }
+
+        return false;
+    }
+
+    protected function getMenuModel()
+    {
+        return config('admin.database.menu_model');
+    }
+}

+ 28 - 28
src/Extend/HasExtension.php

@@ -1,28 +1,28 @@
-<?php
-
-namespace Dcat\Admin\Extend;
-
-trait HasExtension
-{
-    /**
-     * @var ServiceProvider
-     */
-    protected $extension;
-
-    public function setExtension(ServiceProvider $serviceProvider)
-    {
-        $this->extension = $serviceProvider;
-
-        return $this;
-    }
-
-    public function getExtension()
-    {
-        return $this->extension;
-    }
-
-    public function getExtensionName()
-    {
-        return $this->getExtension()->getName();
-    }
-}
+<?php
+
+namespace Dcat\Admin\Extend;
+
+trait HasExtension
+{
+    /**
+     * @var ServiceProvider
+     */
+    protected $extension;
+
+    public function setExtension(ServiceProvider $serviceProvider)
+    {
+        $this->extension = $serviceProvider;
+
+        return $this;
+    }
+
+    public function getExtension()
+    {
+        return $this->extension;
+    }
+
+    public function getExtensionName()
+    {
+        return $this->getExtension()->getName();
+    }
+}

+ 37 - 37
src/Form/Concerns/HasLayout.php

@@ -1,37 +1,37 @@
-<?php
-
-namespace Dcat\Admin\Form\Concerns;
-
-use Closure;
-use Dcat\Admin\Form\Layout;
-
-trait HasLayout
-{
-    /**
-     * @var Layout
-     */
-    protected $layout;
-
-    /**
-     * @param int|float $width
-     * @param Closure   $callback
-     *
-     * @return $this
-     */
-    public function column($width, Closure $callback)
-    {
-        $this->layout()->onlyColumn($width, function () use ($callback) {
-            $callback($this);
-        });
-
-        return $this;
-    }
-
-    /**
-     * @return Layout
-     */
-    public function layout()
-    {
-        return $this->layout ?: ($this->layout = new Layout($this));
-    }
-}
+<?php
+
+namespace Dcat\Admin\Form\Concerns;
+
+use Closure;
+use Dcat\Admin\Form\Layout;
+
+trait HasLayout
+{
+    /**
+     * @var Layout
+     */
+    protected $layout;
+
+    /**
+     * @param int|float $width
+     * @param Closure   $callback
+     *
+     * @return $this
+     */
+    public function column($width, Closure $callback)
+    {
+        $this->layout()->onlyColumn($width, function () use ($callback) {
+            $callback($this);
+        });
+
+        return $this;
+    }
+
+    /**
+     * @return Layout
+     */
+    public function layout()
+    {
+        return $this->layout ?: ($this->layout = new Layout($this));
+    }
+}

+ 1 - 2
src/Form/Field.php

@@ -12,7 +12,6 @@ use Illuminate\Contracts\Support\Arrayable;
 use Illuminate\Contracts\Support\Renderable;
 use Illuminate\Support\Arr;
 use Illuminate\Support\Fluent;
-use Illuminate\Support\Str;
 use Illuminate\Support\Traits\Macroable;
 
 /**
@@ -249,7 +248,7 @@ class Field implements Renderable
      */
     protected function formatLabel($arguments = [])
     {
-        if(isset($arguments[0])) {
+        if (isset($arguments[0])) {
             return $arguments[0];
         }
 

+ 0 - 1
src/Form/Field/Editor.php

@@ -4,7 +4,6 @@ namespace Dcat\Admin\Form\Field;
 
 use Dcat\Admin\Form\Field;
 use Dcat\Admin\Support\Helper;
-use Dcat\Admin\Support\JavaScript;
 
 /**
  * TinyMCE editor.

+ 0 - 1
src/Form/Field/File.php

@@ -4,7 +4,6 @@ namespace Dcat\Admin\Form\Field;
 
 use Dcat\Admin\Contracts\UploadField as UploadFieldInterface;
 use Dcat\Admin\Form\Field;
-use Dcat\Admin\Form\NestedForm;
 use Dcat\Admin\Support\Helper;
 use Dcat\Admin\Support\JavaScript;
 use Illuminate\Support\Arr;

+ 0 - 1
src/Form/NestedForm.php

@@ -390,7 +390,6 @@ class NestedForm extends WidgetForm
     public function __call($method, $arguments)
     {
         if ($field = $this->resolveField($method, $arguments)) {
-
             $this->pushField($field);
 
             return $field;

+ 3 - 1
src/Grid/Column.php

@@ -410,7 +410,9 @@ class Column
      */
     protected function formatLabel($label)
     {
-        if($label) return $label;
+        if ($label) {
+            return $label;
+        }
 
         $label = admin_trans_field($this->name);
 

+ 3 - 1
src/Grid/Filter/AbstractFilter.php

@@ -141,7 +141,9 @@ abstract class AbstractFilter
      */
     protected function formatLabel($label)
     {
-        if($label) return $label;
+        if ($label) {
+            return $label;
+        }
 
         $label = admin_trans_field($this->column);
 

+ 30 - 30
src/Http/Actions/Menu/Visiable.php

@@ -1,30 +1,30 @@
-<?php
-
-namespace Dcat\Admin\Http\Actions\Menu;
-
-use Dcat\Admin\Tree\RowAction;
-
-class Visiable extends RowAction
-{
-    public function handle()
-    {
-        $key = $this->getKey();
-
-        $menuModel = config('admin.database.menu_model');
-        $menu = $menuModel::find($key);
-
-        $menu->update(['show' => $menu->show ? 0 : 1]);
-
-        return $this
-            ->response()
-            ->success(trans('admin.update_succeeded'))
-            ->location('auth/menu');
-    }
-
-    public function title()
-    {
-        $icon = $this->getRow()->show ? 'icon-eye-off' : 'icon-eye';
-
-        return "&nbsp;<i class='feather $icon'></i>&nbsp;";
-    }
-}
+<?php
+
+namespace Dcat\Admin\Http\Actions\Menu;
+
+use Dcat\Admin\Tree\RowAction;
+
+class Visiable extends RowAction
+{
+    public function handle()
+    {
+        $key = $this->getKey();
+
+        $menuModel = config('admin.database.menu_model');
+        $menu = $menuModel::find($key);
+
+        $menu->update(['show' => $menu->show ? 0 : 1]);
+
+        return $this
+            ->response()
+            ->success(trans('admin.update_succeeded'))
+            ->location('auth/menu');
+    }
+
+    public function title()
+    {
+        $icon = $this->getRow()->show ? 'icon-eye-off' : 'icon-eye';
+
+        return "&nbsp;<i class='feather $icon'></i>&nbsp;";
+    }
+}

+ 11 - 11
src/Http/Controllers/ScaffoldController.php

@@ -3,22 +3,22 @@
 namespace Dcat\Admin\Http\Controllers;
 
 use Dcat\Admin\Admin;
-use Illuminate\Support\Arr;
-use Illuminate\Support\Str;
-use Illuminate\Http\Request;
+use Dcat\Admin\Http\Auth\Permission;
 use Dcat\Admin\Layout\Content;
+use Dcat\Admin\Scaffold\ControllerCreator;
+use Dcat\Admin\Scaffold\LangCreator;
+use Dcat\Admin\Scaffold\MigrationCreator;
+use Dcat\Admin\Scaffold\ModelCreator;
+use Dcat\Admin\Scaffold\RepositoryCreator;
 use Dcat\Admin\Support\Helper;
+use Illuminate\Http\Request;
 use Illuminate\Routing\Controller;
+use Illuminate\Support\Arr;
+use Illuminate\Support\Facades\Artisan;
 use Illuminate\Support\Facades\DB;
-use Illuminate\Support\MessageBag;
 use Illuminate\Support\Facades\URL;
-use Dcat\Admin\Http\Auth\Permission;
-use Dcat\Admin\Scaffold\LangCreator;
-use Dcat\Admin\Scaffold\ModelCreator;
-use Illuminate\Support\Facades\Artisan;
-use Dcat\Admin\Scaffold\MigrationCreator;
-use Dcat\Admin\Scaffold\ControllerCreator;
-use Dcat\Admin\Scaffold\RepositoryCreator;
+use Illuminate\Support\MessageBag;
+use Illuminate\Support\Str;
 
 class ScaffoldController extends Controller
 {

+ 0 - 1
src/Http/JsonResponse.php

@@ -393,7 +393,6 @@ class JsonResponse
      * @param mixed ...$params
      *
      * @return $this
-     *
      */
     public static function make(...$params)
     {

+ 18 - 18
src/Layout/Asset.php

@@ -318,7 +318,7 @@ class Asset
         }
 
         if (mb_strpos($name, '@') !== 0) {
-            $name = '@' . $name;
+            $name = '@'.$name;
         }
 
         $this->alias[$name] = $value;
@@ -340,7 +340,7 @@ class Asset
         }
 
         if (mb_strpos($alias, '@') !== 0) {
-            $alias = '@' . $alias;
+            $alias = '@'.$alias;
         }
 
         $this->js($this->alias[$alias]['js'] ?? null);
@@ -354,7 +354,7 @@ class Asset
      */
     public function css($css)
     {
-        if (!$css) {
+        if (! $css) {
             return;
         }
         $this->css = array_merge(
@@ -384,7 +384,7 @@ class Asset
      */
     public function js($js)
     {
-        if (!$js) {
+        if (! $js) {
             return;
         }
         $this->js = array_merge(
@@ -409,7 +409,7 @@ class Asset
 
         $paths = isset($this->alias[$path][$type]) ? (array) $this->alias[$path][$type] : null;
 
-        if (!$paths) {
+        if (! $paths) {
             return $paths;
         }
 
@@ -429,14 +429,14 @@ class Asset
      */
     public function url($path)
     {
-        if (!$path) {
+        if (! $path) {
             return $path;
         }
 
         $path = $this->getRealPath($path);
 
         if (mb_strpos($path, '//') === false) {
-            $path = config('admin.assets_server') . '/' . trim($path, '/');
+            $path = config('admin.assets_server').'/'.trim($path, '/');
         }
 
         return (config('admin.https') || config('admin.secure')) ? secure_asset($path) : asset($path);
@@ -451,7 +451,7 @@ class Asset
      */
     public function getRealPath(?string $path)
     {
-        if (!$this->containsAlias($path)) {
+        if (! $this->containsAlias($path)) {
             return $path;
         }
 
@@ -459,7 +459,7 @@ class Asset
             '/',
             array_map(
                 function ($v) {
-                    if (!$this->isPathAlias($v)) {
+                    if (! $this->isPathAlias($v)) {
                         return $v;
                     }
 
@@ -513,7 +513,7 @@ class Asset
      */
     public function headerJs($js)
     {
-        if (!$js) {
+        if (! $js) {
             return;
         }
 
@@ -543,7 +543,7 @@ class Asset
      */
     public function script($script, bool $direct = false)
     {
-        if (!$script) {
+        if (! $script) {
             return;
         }
         if ($direct) {
@@ -560,7 +560,7 @@ class Asset
      */
     public function style($style)
     {
-        if (!$style) {
+        if (! $style) {
             return;
         }
         $this->style = array_merge($this->style, (array) $style);
@@ -601,7 +601,7 @@ class Asset
         $html = '';
 
         foreach (array_unique($this->css) as &$v) {
-            if (!$paths = $this->get($v, 'css')) {
+            if (! $paths = $this->get($v, 'css')) {
                 continue;
             }
 
@@ -620,13 +620,13 @@ class Asset
      */
     public function withVersionQuery($url)
     {
-        if (!Str::contains($url, '?')) {
+        if (! Str::contains($url, '?')) {
             $url .= '?';
         }
 
-        $ver = 'v' . Admin::VERSION;
+        $ver = 'v'.Admin::VERSION;
 
-        return Str::endsWith($url, '?') ? $url . $ver : $url . '&' . $ver;
+        return Str::endsWith($url, '?') ? $url.$ver : $url.'&'.$ver;
     }
 
     /**
@@ -651,7 +651,7 @@ class Asset
         $html = '';
 
         foreach (array_unique($this->js) as &$v) {
-            if (!$paths = $this->get($v, 'js')) {
+            if (! $paths = $this->get($v, 'js')) {
                 continue;
             }
 
@@ -671,7 +671,7 @@ class Asset
         $html = '';
 
         foreach (array_unique($this->headerJs) as &$v) {
-            if (!$paths = $this->get($v, 'js')) {
+            if (! $paths = $this->get($v, 'js')) {
                 continue;
             }
 

+ 1 - 1
src/Layout/Menu.php

@@ -200,7 +200,7 @@ class Menu
     }
 
     /**
-     * 判断用户
+     * 判断用户.
      *
      * @param array|\Dcat\Admin\Models\Menu $item
      *

+ 4 - 2
src/Show/Field.php

@@ -158,7 +158,9 @@ class Field implements Renderable
      */
     protected function formatLabel($label)
     {
-        if($label) return $label;
+        if ($label) {
+            return $label;
+        }
 
         $label = admin_trans_field($this->name);
 
@@ -256,7 +258,7 @@ class Field implements Renderable
     {
         $field = $this;
 
-        return $this->unescape()->as(function ($path) use ($server , $field) {
+        return $this->unescape()->as(function ($path) use ($server, $field) {
             $name = basename($path);
 
             $field->wrap(false);

+ 0 - 1
src/Traits/HasAuthorization.php

@@ -3,7 +3,6 @@
 namespace Dcat\Admin\Traits;
 
 use Dcat\Admin\Admin;
-use Dcat\Admin\Traits\HasPermissions;
 use Illuminate\Contracts\Auth\Authenticatable;
 use Illuminate\Database\Eloquent\Model;
 

+ 0 - 1
src/Traits/HasHtml.php

@@ -129,7 +129,6 @@ trait HasHtml
                 $script = "(function () {{$script}\n})();";
             }
 
-
             if ($element->hasAttribute('once')) {
                 return static::script($script);
             }

+ 0 - 1
src/Widgets/DialogTable.php

@@ -5,7 +5,6 @@ namespace Dcat\Admin\Widgets;
 use Dcat\Admin\Grid\LazyRenderable;
 use Dcat\Admin\Support\Helper;
 use Illuminate\Contracts\Support\Renderable;
-use Illuminate\Support\Str;
 
 class DialogTable extends Widget
 {

+ 0 - 1
src/Widgets/Form.php

@@ -11,7 +11,6 @@ use Dcat\Admin\Form\Concerns\HasLayout;
 use Dcat\Admin\Form\Concerns\HasRows;
 use Dcat\Admin\Form\Concerns\HasTabs;
 use Dcat\Admin\Form\Field;
-use Dcat\Admin\Form\Layout;
 use Dcat\Admin\Support\Helper;
 use Dcat\Admin\Traits\HasAuthorization;
 use Dcat\Admin\Traits\HasFormResponse;

+ 0 - 1
src/Widgets/Lazy.php

@@ -4,7 +4,6 @@ namespace Dcat\Admin\Widgets;
 
 use Dcat\Admin\Contracts\LazyRenderable;
 use Dcat\Admin\Traits\InteractsWithRenderApi;
-use Illuminate\Support\Str;
 
 class Lazy extends Widget
 {

+ 2 - 2
src/Widgets/LazyTable.php

@@ -120,8 +120,8 @@ JS;
      */
     protected function getLoadScript()
     {
-        return <<<JS
-\$this.trigger('table:load');
+        return <<<'JS'
+$this.trigger('table:load');
 JS;
     }