Code Duplication    Length = 30-30 lines in 2 locations

src/Grid/Filter/Presenter/Select.php 1 location

@@ 111-140 (lines=30) @@
108
     *
109
     * @return $this
110
     */
111
    public function model($model, $idField = 'id', $textField = 'name')
112
    {
113
        if (!class_exists($model)
114
            || !in_array(Model::class, class_parents($model))
115
        ) {
116
            throw new \InvalidArgumentException("[$model] must be a valid model class");
117
        }
118
119
        $this->options = function ($value) use ($model, $idField, $textField) {
120
            if (empty($value)) {
121
                return [];
122
            }
123
124
            $resources = [];
125
126
            if (is_array($value)) {
127
                if (Arr::isAssoc($value)) {
128
                    $resources[] = array_get($value, $idField);
129
                } else {
130
                    $resources = array_column($value, $idField);
131
                }
132
            } else {
133
                $resources[] = $value;
134
            }
135
136
            return $model::find($resources)->pluck($textField, $idField)->toArray();
137
        };
138
139
        return $this;
140
    }
141
142
    /**
143
     * Load options from remote.

src/Form/Field/Select.php 1 location

@@ 302-331 (lines=30) @@
299
     *
300
     * @return $this
301
     */
302
    public function model($model, $idField = 'id', $textField = 'name')
303
    {
304
        if (
305
            !class_exists($model)
306
            || !in_array(Model::class, class_parents($model))
307
        ) {
308
            throw new \InvalidArgumentException("[$model] must be a valid model class");
309
        }
310
311
        $this->options = function ($value) use ($model, $idField, $textField) {
312
            if (empty($value)) {
313
                return [];
314
            }
315
316
            $resources = [];
317
318
            if (is_array($value)) {
319
                if (Arr::isAssoc($value)) {
320
                    $resources[] = array_get($value, $idField);
321
                } else {
322
                    $resources = array_column($value, $idField);
323
                }
324
            } else {
325
                $resources[] = $value;
326
            }
327
328
            return $model::find($resources)->pluck($textField, $idField)->toArray();
329
        };
330
331
        return $this;
332
    }
333
334
    /**