Browse Source

Merge pull request #311 from jqhph/analysis-d0eb39

Apply fixes from StyleCI
Jiang Qinghua 4 years ago
parent
commit
1888050527

+ 25 - 25
src/Form/Concerns/HandleCascadeFields.php

@@ -1,25 +1,25 @@
-<?php
-
-namespace Dcat\Admin\Form\Concerns;
-
-use Dcat\Admin\Form\Field;
-
-trait HandleCascadeFields
-{
-    /**
-     * @param array    $dependency
-     * @param \Closure $closure
-     *
-     * @return Field\CascadeGroup
-     */
-    public function cascadeGroup(\Closure $closure, array $dependency)
-    {
-        $this->pushField($group = new Field\CascadeGroup($dependency));
-
-        call_user_func($closure, $this);
-
-        $group->end();
-
-        return $group;
-    }
-}
+<?php
+
+namespace Dcat\Admin\Form\Concerns;
+
+use Dcat\Admin\Form\Field;
+
+trait HandleCascadeFields
+{
+    /**
+     * @param array    $dependency
+     * @param \Closure $closure
+     *
+     * @return Field\CascadeGroup
+     */
+    public function cascadeGroup(\Closure $closure, array $dependency)
+    {
+        $this->pushField($group = new Field\CascadeGroup($dependency));
+
+        call_user_func($closure, $this);
+
+        $group->end();
+
+        return $group;
+    }
+}

+ 162 - 162
src/Form/Field/CanCascadeFields.php

@@ -1,124 +1,124 @@
-<?php
-
-namespace Dcat\Admin\Form\Field;
-
-use Dcat\Admin\Admin;
-use Dcat\Admin\Form;
-use Illuminate\Support\Arr;
-
-/**
- * @property Form $form
- */
-trait CanCascadeFields
-{
-    /**
-     * @var array
-     */
-    protected $conditions = [];
-
-    /**
-     * @var array
-     */
-    protected $cascadeGroups = [];
-
-    /**
-     * @param $operator
-     * @param $value
-     * @param $closure
-     *
-     * @return $this
-     */
-    public function when($operator, $value, $closure = null)
-    {
-        if (func_num_args() == 2) {
-            $closure = $value;
-            $value = $operator;
-            $operator = $this->getDefaultOperator();
-        }
-
-        $this->formatValues($operator, $value);
-
-        $this->addDependents($operator, $value, $closure);
-
-        return $this;
-    }
-
-    protected function getDefaultOperator()
-    {
-        if ($this instanceof MultipleSelect || $this instanceof Checkbox) {
-            return 'in';
-        }
-
-        return '=';
-    }
-
-    /**
-     * @param string $operator
-     * @param mixed  $value
-     */
-    protected function formatValues(string $operator, &$value)
-    {
-        if (in_array($operator, ['in', 'notIn'])) {
-            $value = Arr::wrap($value);
-        }
-
-        if (is_array($value)) {
-            $value = array_map('strval', $value);
-        } else {
-            $value = strval($value);
-        }
-    }
-
-    /**
-     * @param string   $operator
-     * @param mixed    $value
-     * @param \Closure $closure
-     */
-    protected function addDependents(string $operator, $value, \Closure $closure)
-    {
-        $this->conditions[] = compact('operator', 'value', 'closure');
-
-        $this->form->cascadeGroup($closure, [
-            'column' => $this->column(),
-            'index'  => count($this->conditions) - 1,
-            'class'  => $this->getCascadeClass($value),
-        ]);
-    }
-
-    /**
-     * @param mixed $value
-     *
-     * @return string
-     */
-    protected function getCascadeClass($value)
-    {
-        if (is_array($value)) {
-            $value = implode('-', $value);
-        }
-
-        return sprintf('cascade-%s-%s', $this->getElementClassString(), $value);
-    }
-
-    /**
-     * Add cascade scripts to contents.
-     *
-     * @return void
-     */
-    protected function addCascadeScript()
-    {
-        if (empty($this->conditions)) {
-            return;
-        }
-
-        $cascadeGroups = collect($this->conditions)->map(function ($condition) {
-            return [
-                'class'    => $this->getCascadeClass($condition['value']),
-                'operator' => $condition['operator'],
-                'value'    => $condition['value'],
-            ];
-        })->toJson();
-
-        $script = <<<JS
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Admin;
+use Dcat\Admin\Form;
+use Illuminate\Support\Arr;
+
+/**
+ * @property Form $form
+ */
+trait CanCascadeFields
+{
+    /**
+     * @var array
+     */
+    protected $conditions = [];
+
+    /**
+     * @var array
+     */
+    protected $cascadeGroups = [];
+
+    /**
+     * @param $operator
+     * @param $value
+     * @param $closure
+     *
+     * @return $this
+     */
+    public function when($operator, $value, $closure = null)
+    {
+        if (func_num_args() == 2) {
+            $closure = $value;
+            $value = $operator;
+            $operator = $this->getDefaultOperator();
+        }
+
+        $this->formatValues($operator, $value);
+
+        $this->addDependents($operator, $value, $closure);
+
+        return $this;
+    }
+
+    protected function getDefaultOperator()
+    {
+        if ($this instanceof MultipleSelect || $this instanceof Checkbox) {
+            return 'in';
+        }
+
+        return '=';
+    }
+
+    /**
+     * @param string $operator
+     * @param mixed  $value
+     */
+    protected function formatValues(string $operator, &$value)
+    {
+        if (in_array($operator, ['in', 'notIn'])) {
+            $value = Arr::wrap($value);
+        }
+
+        if (is_array($value)) {
+            $value = array_map('strval', $value);
+        } else {
+            $value = strval($value);
+        }
+    }
+
+    /**
+     * @param string   $operator
+     * @param mixed    $value
+     * @param \Closure $closure
+     */
+    protected function addDependents(string $operator, $value, \Closure $closure)
+    {
+        $this->conditions[] = compact('operator', 'value', 'closure');
+
+        $this->form->cascadeGroup($closure, [
+            'column' => $this->column(),
+            'index'  => count($this->conditions) - 1,
+            'class'  => $this->getCascadeClass($value),
+        ]);
+    }
+
+    /**
+     * @param mixed $value
+     *
+     * @return string
+     */
+    protected function getCascadeClass($value)
+    {
+        if (is_array($value)) {
+            $value = implode('-', $value);
+        }
+
+        return sprintf('cascade-%s-%s', $this->getElementClassString(), $value);
+    }
+
+    /**
+     * Add cascade scripts to contents.
+     *
+     * @return void
+     */
+    protected function addCascadeScript()
+    {
+        if (empty($this->conditions)) {
+            return;
+        }
+
+        $cascadeGroups = collect($this->conditions)->map(function ($condition) {
+            return [
+                'class'    => $this->getCascadeClass($condition['value']),
+                'operator' => $condition['operator'],
+                'value'    => $condition['value'],
+            ];
+        })->toJson();
+
+        $script = <<<JS
 (function () {
     var compare = function (a, b, o) {
         if ($.isArray(b)) {
@@ -159,44 +159,44 @@ trait CanCascadeFields
     var cascade_groups = {$cascadeGroups}, event = '{$this->cascadeEvent}';
 
     $('{$this->getElementClassSelector()}').on(event, function (e) {
-        {$this->getFormFrontValue()}
-
-        cascade_groups.forEach(function (event) {
-            var group = $('div.cascade-group.'+event.class);
-            if (compare(checked, event.value, event.operator)) {
-                group.removeClass('d-none');
-            } else {
-                group.addClass('d-none');
-            }
-        });
-    }).trigger(event);
-})();
-JS;
-
-        Admin::script($script);
-    }
-
-    /**
-     * @return string
-     */
-    protected function getFormFrontValue()
-    {
-        switch (get_class($this)) {
-            case Select::class:
-            case MultipleSelect::class:
-                return 'var checked = $(this).val();';
-            case Radio::class:
-                return <<<JS
-var checked = $('{$this->getElementClassSelector()}:checked').val();
-JS;
-            case Checkbox::class:
-                return <<<JS
-var checked = $('{$this->getElementClassSelector()}:checked').map(function(){
-  return $(this).val();
-}).get();
-JS;
-            default:
-                throw new \InvalidArgumentException('Invalid form field type');
-        }
-    }
-}
+        {$this->getFormFrontValue()}
+
+        cascade_groups.forEach(function (event) {
+            var group = $('div.cascade-group.'+event.class);
+            if (compare(checked, event.value, event.operator)) {
+                group.removeClass('d-none');
+            } else {
+                group.addClass('d-none');
+            }
+        });
+    }).trigger(event);
+})();
+JS;
+
+        Admin::script($script);
+    }
+
+    /**
+     * @return string
+     */
+    protected function getFormFrontValue()
+    {
+        switch (get_class($this)) {
+            case Select::class:
+            case MultipleSelect::class:
+                return 'var checked = $(this).val();';
+            case Radio::class:
+                return <<<JS
+var checked = $('{$this->getElementClassSelector()}:checked').val();
+JS;
+            case Checkbox::class:
+                return <<<JS
+var checked = $('{$this->getElementClassSelector()}:checked').map(function(){
+  return $(this).val();
+}).get();
+JS;
+            default:
+                throw new \InvalidArgumentException('Invalid form field type');
+        }
+    }
+}

+ 72 - 72
src/Form/Field/CascadeGroup.php

@@ -1,72 +1,72 @@
-<?php
-
-namespace Dcat\Admin\Form\Field;
-
-use Dcat\Admin\Form\Field;
-
-class CascadeGroup extends Field
-{
-    /**
-     * @var array
-     */
-    protected $dependency;
-
-    /**
-     * @var string
-     */
-    protected $hide = 'd-none';
-
-    /**
-     * CascadeGroup constructor.
-     *
-     * @param array $dependency
-     */
-    public function __construct(array $dependency)
-    {
-        $this->dependency = $dependency;
-    }
-
-    /**
-     * @param Field $field
-     *
-     * @return bool
-     */
-    public function dependsOn(Field $field)
-    {
-        return $this->dependency['column'] == $field->column();
-    }
-
-    /**
-     * @return int
-     */
-    public function index()
-    {
-        return $this->dependency['index'];
-    }
-
-    /**
-     * @return void
-     */
-    public function visiable()
-    {
-        $this->hide = '';
-    }
-
-    /**
-     * @return string
-     */
-    public function render()
-    {
-        return <<<HTML
-<div class="cascade-group {$this->dependency['class']} {$this->hide}">
-HTML;
-    }
-
-    /**
-     * @return void
-     */
-    public function end()
-    {
-        $this->form->html('</div>')->plain();
-    }
-}
+<?php
+
+namespace Dcat\Admin\Form\Field;
+
+use Dcat\Admin\Form\Field;
+
+class CascadeGroup extends Field
+{
+    /**
+     * @var array
+     */
+    protected $dependency;
+
+    /**
+     * @var string
+     */
+    protected $hide = 'd-none';
+
+    /**
+     * CascadeGroup constructor.
+     *
+     * @param array $dependency
+     */
+    public function __construct(array $dependency)
+    {
+        $this->dependency = $dependency;
+    }
+
+    /**
+     * @param Field $field
+     *
+     * @return bool
+     */
+    public function dependsOn(Field $field)
+    {
+        return $this->dependency['column'] == $field->column();
+    }
+
+    /**
+     * @return int
+     */
+    public function index()
+    {
+        return $this->dependency['index'];
+    }
+
+    /**
+     * @return void
+     */
+    public function visiable()
+    {
+        $this->hide = '';
+    }
+
+    /**
+     * @return string
+     */
+    public function render()
+    {
+        return <<<HTML
+<div class="cascade-group {$this->dependency['class']} {$this->hide}">
+HTML;
+    }
+
+    /**
+     * @return void
+     */
+    public function end()
+    {
+        $this->form->html('</div>')->plain();
+    }
+}

+ 1 - 1
src/Form/Row.php

@@ -2,8 +2,8 @@
 
 namespace Dcat\Admin\Form;
 
-use Dcat\Admin\Widgets\Form as WidgetForm;
 use Dcat\Admin\Form;
+use Dcat\Admin\Widgets\Form as WidgetForm;
 use Illuminate\Contracts\Support\Renderable;
 
 /**

+ 1 - 1
src/Form/Tab.php

@@ -3,8 +3,8 @@
 namespace Dcat\Admin\Form;
 
 use Dcat\Admin\Admin;
-use Dcat\Admin\Widgets\Form as WidgetForm;
 use Dcat\Admin\Form;
+use Dcat\Admin\Widgets\Form as WidgetForm;
 use Illuminate\Support\Collection;
 
 class Tab