DataColumn   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 143
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 21
eloc 35
c 1
b 0
f 0
dl 0
loc 143
ccs 41
cts 41
cp 1
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
A getProperty() 0 3 1
A getBodyAttributes() 0 3 1
A getFooter() 0 3 1
A getFilterType() 0 3 1
A getHeaderAttributes() 0 3 1
A __construct() 0 22 2
A getFilterInputSelectPrompt() 0 3 1
A getHeader() 0 3 1
A isWithSorting() 0 3 1
A getColumnAttributes() 0 3 1
A getFilterInputAttributes() 0 3 1
A getFilterModelName() 0 3 1
A isVisible() 0 3 1
A getFilter() 0 3 1
A getRenderer() 0 3 1
A getFilterInputSelectItems() 0 3 1
A getFilterAttributes() 0 3 1
A getFilterValueDefault() 0 3 1
A getFilterProperty() 0 3 1
A getContent() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\DataView\Column;
6
7
use InvalidArgumentException;
8
use Stringable;
9
use Yiisoft\Yii\DataView\Column\Base\Cell;
10
use Yiisoft\Yii\DataView\Helper\Attribute;
11
12
use function sprintf;
13
14
/**
15
 * DetailColumn is the default column type for the {@see GridView} widget.
16
 *
17
 * It is used to show data columns and allows {@see withSorting|sorting} and {@see filter|filtering} them.
18
 *
19
 * A simple data column definition refers to an attribute in the data of the GridView's data provider.
20
 *
21
 * The name of the attribute is specified by {@see attribute}.
22
 *
23
 * By setting {@see value} and {@see label}, the label and cell content can be customized.
24
 *
25
 * A data column differentiates between the {@see getDataCellValue|data cell value} and the
26
 * {@see renderDataCellContent|data cell content}. The cell value is an un-formatted value that may be used for
27
 * calculation, while the actual cell content is a {@see format|formatted} version of that value which may contain HTML
28
 * markup.
29
 */
30
final class DataColumn implements ColumnInterface
31
{
32
    /** @psalm-var string[] */
33
    private array $filterTypes = [
34
        'date' => 'date',
35
        'datetime' => 'datetime-local',
36
        'email' => 'email',
37
        'month' => 'month',
38
        'number' => 'number',
39
        'range' => 'range',
40
        'search' => 'search',
41
        'select' => 'select',
42
        'tel' => 'tel',
43
        'text' => 'text',
44
        'time' => 'time',
45
        'url' => 'url',
46
        'week' => 'week',
47
    ];
48
49
    /**
50
     * @psalm-param array<array-key, string|array<array-key,string>> $filterInputSelectItems
51
     */
52 70
    public function __construct(
53
        private ?string $property = null,
54
        private ?string $header = null,
55
        private ?string $footer = null,
56
        private array $columnAttributes = [],
57
        private array $headerAttributes = [],
58
        private array $filterAttributes = [],
59
        private array $bodyAttributes = [],
60
        private bool $withSorting = true,
61
        private mixed $content = null,
62
        private ?string $filter = null,
63
        private ?string $filterProperty = null,
64
        private string $filterType = 'text',
65
        private array $filterInputAttributes = [],
66
        private ?string $filterModelName = null,
67
        private Stringable|null|string|int|bool|float $filterValueDefault = null,
68
        private array $filterInputSelectItems = [],
69
        private string $filterInputSelectPrompt = '',
70
        private bool $visible = true,
71
    ) {
72 70
        if (!isset($this->filterTypes[$filterType])) {
73 1
            throw new InvalidArgumentException(sprintf('Invalid filter type "%s".', $filterType));
74
        }
75
    }
76
77 68
    public function getProperty(): ?string
78
    {
79 68
        return $this->property;
80
    }
81
82 67
    public function getHeader(): ?string
83
    {
84 67
        return $this->header;
85
    }
86
87 2
    public function getFooter(): ?string
88
    {
89 2
        return $this->footer;
90
    }
91
92 2
    public function getColumnAttributes(): array
93
    {
94 2
        return $this->columnAttributes;
95
    }
96
97 66
    public function getHeaderAttributes(): array
98
    {
99 66
        return $this->headerAttributes;
100
    }
101
102 18
    public function getFilterAttributes(): array
103
    {
104 18
        return $this->filterAttributes;
105
    }
106
107 63
    public function getBodyAttributes(): array
108
    {
109 63
        return $this->bodyAttributes;
110
    }
111
112 67
    public function isWithSorting(): bool
113
    {
114 67
        return $this->withSorting;
115
    }
116
117 63
    public function getContent(): mixed
118
    {
119 63
        return $this->content;
120
    }
121
122 68
    public function getFilter(): ?string
123
    {
124 68
        return $this->filter;
125
    }
126
127 67
    public function getFilterProperty(): ?string
128
    {
129 67
        return $this->filterProperty;
130
    }
131
132 17
    public function getFilterType(): string
133
    {
134 17
        return $this->filterTypes[$this->filterType];
135
    }
136
137 17
    public function getFilterInputAttributes(): array
138
    {
139 17
        return $this->filterInputAttributes;
140
    }
141
142 17
    public function getFilterModelName(): ?string
143
    {
144 17
        return $this->filterModelName;
145
    }
146
147 17
    public function getFilterValueDefault(): float|Stringable|bool|int|string|null
148
    {
149 17
        return $this->filterValueDefault;
150
    }
151
152
    /**
153
     * @psalm-return array<array-key, string|array<array-key,string>>
154
     */
155 1
    public function getFilterInputSelectItems(): array
156
    {
157 1
        return $this->filterInputSelectItems;
158
    }
159
160 1
    public function getFilterInputSelectPrompt(): string
161
    {
162 1
        return $this->filterInputSelectPrompt;
163
    }
164
165 68
    public function isVisible(): bool
166
    {
167 68
        return $this->visible;
168
    }
169
170 68
    public function getRenderer(): string
171
    {
172 68
        return DataColumnRenderer::class;
173
    }
174
}
175