Completed
Push — master ( e2a3b3...5d4b38 )
by wen
02:54
created

Column::isSortable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
4
namespace Sco\Admin\View\Columns;
5
6
use JsonSerializable;
7
use Illuminate\Contracts\Support\Arrayable;
8
use Illuminate\Contracts\Support\Jsonable;
9
use Sco\Admin\Contracts\ColumnInterface;
10
11
abstract class Column implements ColumnInterface, Arrayable, Jsonable, JsonSerializable
12
{
13
    protected $name;
14
15
    protected $label;
16
17
    protected $width = 0;
18
19
    protected $minWidth = 80;
20
21
    protected $sortable = false;
22
23
    protected $fixed = false;
24
25
    public function __construct($name, $label)
26
    {
27
        $this->name  = $name;
28
        $this->label = $label;
29
    }
30
31
    public function getName()
32
    {
33
        return $this->name;
34
    }
35
36
    public function setWidth($width)
37
    {
38
        $this->width = $width;
39
    }
40
41
    public function setMinWidth($width)
42
    {
43
        $this->minWidth = $width;
44
    }
45
46
    public function isSortable()
47
    {
48
        $this->sortable = true;
49
    }
50
51
    public function isCustomSortable()
52
    {
53
        $this->sortable = 'custom';
0 ignored issues
show
Documentation Bug introduced by
The property $sortable was declared of type boolean, but 'custom' is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
54
        // TODO
55
        // register sort route
56
57
    }
58
59
    public function isFixed()
60
    {
61
        $this->fixed = true;
62
    }
63
64
    public function toArray()
65
    {
66
        return [
67
            'name'     => $this->getName(),
68
            'label'    => $this->label,
69
            'width'    => $this->width,
70
            'fixed'    => $this->fixed,
71
            'minWidth' => $this->minWidth,
72
            'sortable' => $this->sortable,
73
        ];
74
    }
75
76
    public function jsonSerialize()
77
    {
78
        return $this->toArray();
79
    }
80
81
    public function toJson($options = 0)
82
    {
83
        return json_encode($this->jsonSerialize(), $options);
84
    }
85
86
    public function __toString()
87
    {
88
        return $this->toJson();
89
    }
90
}
91