Completed
Push — master ( 77dbd7...6a8ad9 )
by wen
26:38
created

Element   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 59
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getModel() 0 4 1
A setModel() 0 6 1
A toArray() 0 8 1
A jsonSerialize() 0 4 1
A toJson() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
4
namespace Sco\Admin\Form\Elements;
5
6
use Illuminate\Database\Eloquent\Model;
7
use JsonSerializable;
8
use Illuminate\Contracts\Support\Arrayable;
9
use Illuminate\Contracts\Support\Jsonable;
10
use Sco\Admin\Contracts\Form\Elements\ElementInterface;
11
use Sco\Admin\Contracts\WithModel;
12
13
abstract class Element implements
14
    ElementInterface,
15
    WithModel,
16
    Arrayable,
17
    Jsonable,
18
    JsonSerializable
19
{
20
    protected $type;
21
22
    protected $name;
23
    protected $title;
24
25
    /**
26
     * @var \Illuminate\Database\Eloquent\Model
27
     */
28
    protected $model;
29
30
    public function __construct($name, $title)
31
    {
32
        $this->name  = $name;
33
        $this->title = $title;
34
    }
35
36
    public function getModel()
37
    {
38
        return $this->model;
39
    }
40
41
    public function setModel(Model $model)
42
    {
43
        $this->model = $model;
44
45
        return $this;
46
    }
47
48
    public function toArray()
49
    {
50
        return [
51
            'key'   => $this->name,
52
            'title' => $this->title,
53
            'type'  => $this->type,
54
        ];
55
    }
56
57
    public function jsonSerialize()
58
    {
59
        return $this->toArray();
60
    }
61
62
    public function toJson($options = 0)
63
    {
64
        return json_encode($this->jsonSerialize(), $options);
65
    }
66
67
    public function __toString()
68
    {
69
        return $this->toJson();
70
    }
71
}
72