Completed
Push — master ( c239db...b86bbe )
by wen
02:42
created

Field   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 2
cbo 0
dl 0
loc 42
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isRelationship() 0 4 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\Fields;
5
6
use JsonSerializable;
7
use Illuminate\Contracts\Support\Arrayable;
8
use Illuminate\Contracts\Support\Jsonable;
9
use Sco\Admin\Contracts\Field as FieldContract;
10
11
abstract class Field implements FieldContract, Arrayable, Jsonable, JsonSerializable
12
{
13
    protected $type;
14
15
    protected $name;
16
    protected $title;
17
18
    public function __construct($name, $title)
19
    {
20
        $this->name  = $name;
21
        $this->title = $title;
22
    }
23
24
    public function isRelationship()
25
    {
26
        return !empty($this->relationship);
0 ignored issues
show
Bug introduced by
The property relationship does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
    }
28
29
    public function toArray()
30
    {
31
        return [
32
            'key'   => $this->name,
33
            'title' => $this->title,
34
            'type'  => $this->type,
35
        ];
36
    }
37
38
    public function jsonSerialize()
39
    {
40
        return $this->toArray();
41
    }
42
43
    public function toJson($options = 0)
44
    {
45
        return json_encode($this->jsonSerialize(), $options);
46
    }
47
48
    public function __toString()
49
    {
50
        return $this->toJson();
51
    }
52
}
53