Code Duplication    Length = 26-26 lines in 2 locations

src/Form/Elements/Select.php 1 location

@@ 47-72 (lines=26) @@
44
    /**
45
     * @return \Illuminate\Support\Collection
46
     */
47
    public function getOptions()
48
    {
49
        if ($this->options instanceof \Closure) {
50
            $options = ($this->options)();
51
        } elseif (is_string($this->options) || $this->options instanceof Model) {
52
            $options = $this->setOptionsFromModel();
53
        } elseif (is_array($this->options)) {
54
            $options = $this->options;
55
        } else {
56
            throw new InvalidArgumentException(
57
                sprintf(
58
                    "The form %s element's options must be return array(key=>value)",
59
                    $this->getType()
60
                )
61
            );
62
        }
63
64
        return collect($options)->mapWithKeys(function ($value, $key) {
65
            return [
66
                $key => [
67
                    'label' => $value,
68
                    'value' => (string)$key,
69
                ],
70
            ];
71
        })->values();
72
    }
73
74
    /**
75
     * @param mixed $options

src/Form/Elements/Tree.php 1 location

@@ 56-81 (lines=26) @@
53
        return method_exists($this->getModel(), $this->getName());
54
    }
55
56
    public function getOptions()
57
    {
58
        if ($this->options instanceof \Closure) {
59
            $options = ($this->options)();
60
        } elseif (is_string($this->options) || $this->options instanceof Model) {
61
            $options = $this->setOptionsFromModel();
62
        } elseif (is_array($this->options)) {
63
            $options = $this->options;
64
        } else {
65
            throw new InvalidArgumentException(
66
                sprintf(
67
                    "The form %s element's options must be return array(key=>value)",
68
                    $this->getType()
69
                )
70
            );
71
        }
72
73
        return collect($options)->mapWithKeys(function ($value, $key) {
74
            return [
75
                $key => [
76
                    'id' => (string)$key,
77
                    'label' => $value,
78
                ],
79
            ];
80
        })->values();
81
    }
82
83
    /**
84
     * @param mixed $options