Column   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 42
ccs 0
cts 17
cp 0
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 3
A setFieldsKeys() 0 5 1
A sortable() 0 5 1
A toArray() 0 7 1
1
<?php
2
3
namespace InertiaDashboardKit\Adapt\Columns;
4
5
abstract class Column
6
{
7
    protected string $component = '';
8
9
    protected bool $sortable = false;
10
11
    protected ?string $title = null;
12
13
    protected string $field;
14
15
    public function __construct(?string $title = null)
16
    {
17
        $this->title = $title ?? $this->title;
18
        if (is_null($this->title)) {
19
            $this->title = __(class_basename(static::class));
20
        }
21
        if (!$this->component) {
22
            $this->component = 'IndexColumn'.class_basename(static::class);
23
        }
24
    }
25
26
    public function setFieldsKeys(...$args): static
27
    {
28
        $this->field = $args[0] ?? '';
29
30
        return $this;
31
    }
32
33
    public function sortable(bool $sortable = true): static
34
    {
35
        $this->sortable = $sortable;
36
37
        return $this;
38
    }
39
40
    public function toArray(): array
41
    {
42
        return [
43
            'component' => $this->component,
44
            'sortable'  => $this->sortable,
45
            'title'     => $this->title,
46
            'field'     => $this->field,
47
        ];
48
    }
49
}
50