Completed
Push — master ( 675c3f...4830ba )
by wen
11:40
created

Select::parseOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 11
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Sco\Admin\Form\Elements;
4
5
use Illuminate\Database\Eloquent\Model;
6
use InvalidArgumentException;
7
use Sco\Admin\Contracts\RepositoryInterface;
8
use Sco\Admin\Form\Elements\Concerns\HasOptions;
9
10
class Select extends NamedElement
11
{
12
    use HasOptions;
13
14
    protected $type = 'select';
15
16
    protected $size = '';
17
18
    public function __construct($name, $title, $options)
19
    {
20
        parent::__construct($name, $title);
21
22
        $this->setOptions($options);
23
    }
24
25
    public function getSize()
26
    {
27
        return $this->size;
28
    }
29
30
    public function setSize($value)
31
    {
32
        $this->size = $value;
33
34
        return $this;
35
    }
36
37
    public function getValue()
38
    {
39
        return (string)parent::getValue();
40
    }
41
42 View Code Duplication
    protected function parseOptions($options)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
    {
44
        return collect($options)->mapWithKeys(function ($value, $key) {
45
            return [
46
                $key => [
47
                    'label' => $value,
48
                    'value' => (string)$key,
49
                ],
50
            ];
51
        })->values();
52
    }
53
54
    public function toArray()
55
    {
56
        return parent::toArray() + [
57
                'options' => $this->getOptions(),
58
                'size'    => $this->getSize(),
59
            ];
60
    }
61
}
62