Completed
Push — master ( 032e9a...f4f4f4 )
by Arjay
05:40
created

Field::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Editor;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Support\Fluent;
7
8
class Field extends Fluent
9
{
10
    /**
11
     * Field type.
12
     *
13
     * @var string
14
     */
15
    protected $type = 'text';
16
17
    /**
18
     * Password constructor.
19
     */
20
    public function __construct($attributes = [])
21
    {
22
        $attributes['type'] = $attributes['type'] ?? $this->type;
23
24
        parent::__construct($attributes);
25
    }
26
27
    /**
28
     * @param string $name
29
     * @param string $label
30
     * @return Field|Select|Password|DateTime|Checkbox|Radio|Hidden|ReadOnly|TextArea
31
     */
32
    public static function make($name, $label = '')
33
    {
34
        if (is_array($name)) {
35
            return new static($name);
36
        }
37
38
        $data = [
39
            'name'  => $name,
40
            'label' => $label ?: Str::title($name),
41
        ];
42
43
        return new static($data);
44
    }
45
46
    /**
47
     * @param string $label
48
     * @return $this
49
     */
50
    public function label($label)
51
    {
52
        $this->attributes['label'] = $label;
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param string $name
59
     * @return $this
60
     */
61
    public function name($name)
62
    {
63
        $this->attributes['name'] = $name;
64
65
        return $this;
66
    }
67
68
    /**
69
     * @param string $data
70
     * @return $this
71
     */
72
    public function data($data)
73
    {
74
        $this->attributes['data'] = $data;
75
76
        return $this;
77
    }
78
79
    /**
80
     * @param string $type
81
     * @return $this
82
     */
83
    public function type($type)
84
    {
85
        $this->attributes['type'] = $type;
86
87
        return $this;
88
    }
89
}
90