Skip to content

Commit c6dc6d8

Browse files
authored
TypeHint/PHPDoc Tidying (#2246)
* Fix broken typehints * Minor tweaks to Footer/SecondaryHeader to ensure presence of callback prior to executing * Fix styling * PHPDoc additions * Fix styling * Update ChangeLog for TypeHintFixes * Fix styling * FilterPillData and StandardFilterPillData phpdocs * Fix styling
1 parent 6f25fcc commit c6dc6d8

File tree

9 files changed

+165
-43
lines changed

9 files changed

+165
-43
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to `laravel-livewire-tables` will be documented in this file
44

5+
## PREVIEW
6+
### Tweaks
7+
- Tidying PHPDocs by @lrljoe in https://github.com/rappasoft/laravel-livewire-tables/pull/2246
8+
59
## [v3.7.1] - 2025-02-28
610
### Bug Fixes
711
- Ensure that LinkColumn is included in query if "from" is defined

phpstan.neon

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@ parameters:
2727
- src/Traits/Helpers/QueryHelpers.php
2828
- src/Views/Columns/Traits/HasSlot.php
2929
- src/Views/Columns/Traits/Helpers/ArrayColumnHelpers.php
30-
- identifier: instanceof.alwaysTrue
31-
paths:
32-
- src/Views/Columns/Traits/HasFooter.php
33-
- src/Views/Columns/Traits/HasSecondaryHeader.php
3430
- identifier: function.alreadyNarrowedType
3531
paths:
3632
- src/Views/Columns/Traits/Helpers/ArrayColumnHelpers.php
@@ -41,3 +37,6 @@ parameters:
4137
- src/Views/Filters/Traits/HasOptions.php
4238
- src/Views/Traits/Core/HasTheme.php
4339
- src/Views/Traits/Core/HasView.php
40+
- identifier: unset.possiblyHookedProperty
41+
paths:
42+
- src/Traits/Configuration/CollapsingColumnConfiguration.php

src/DataTransferObjects/DebuggableData.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66

77
class DebuggableData
88
{
9-
public DataTableComponent $component;
10-
11-
public function __construct(DataTableComponent $component)
12-
{
13-
$this->component = $component;
14-
}
9+
public function __construct(public DataTableComponent $component) {}
1510

11+
/**
12+
* Returns data to an array
13+
*
14+
* @return array<mixed>
15+
*/
1616
public function toArray(): array
1717
{
1818
return [

src/DataTransferObjects/FilterGenericData.php

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,13 @@
44

55
class FilterGenericData
66
{
7-
public string $tableName;
8-
9-
public string $filterLayout;
10-
11-
public bool $isTailwind = false;
12-
13-
public bool $isBootstrap4 = false;
14-
15-
public bool $isBootstrap5 = false;
16-
17-
public function __construct(string $tableName, string $filterLayout, bool $isTailwind = false, bool $isBootstrap4 = false, bool $isBootstrap5 = false)
18-
{
19-
$this->tableName = $tableName;
20-
$this->filterLayout = $filterLayout;
21-
$this->isTailwind = $isTailwind;
22-
$this->isBootstrap4 = $isBootstrap4;
23-
$this->isBootstrap5 = $isBootstrap5;
24-
}
7+
public function __construct(public string $tableName, public string $filterLayout, public bool $isTailwind = false, public bool $isBootstrap4 = false, public bool $isBootstrap5 = false) {}
258

9+
/**
10+
* Convert To Array
11+
*
12+
* @return array<mixed>
13+
*/
2614
public function toArray(): array
2715
{
2816
return [

src/DataTransferObjects/Filters/FilterPillData.php

Lines changed: 103 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,61 +31,109 @@ public static function make(string $filterKey, string $filterPillTitle, string|a
3131
return new self($filterKey, $filterPillTitle, $filterPillValue, $separator, $isAnExternalLivewireFilter, $hasCustomPillBlade, $customPillBlade, $filterPillsItemAttributes, $renderPillsAsHtml, $watchForEvents, $customResetButtonAttributes, $renderPillsTitleAsHtml);
3232
}
3333

34+
/**
35+
* Get the Filter Key
36+
*/
37+
public function getFilterKey(): string
38+
{
39+
return $this->filterKey;
40+
}
41+
42+
/**
43+
* Get the title for the Filter Pill
44+
*/
3445
public function getTitle(): string
3546
{
3647
return $this->filterPillTitle;
3748
}
3849

50+
/**
51+
* Get The Filter Pill Value
52+
*
53+
* @return array<mixed>|string|null
54+
*/
3955
public function getPillValue(): array|string|null
4056
{
4157
return $this->filterPillValue;
4258
}
4359

60+
/**
61+
* Determing if there is a Custom Pill blade set
62+
*/
4463
public function getHasCustomPillBlade(): bool
4564
{
46-
return $this->hasCustomPillBlade ?? false;
65+
return $this->hasCustomPillBlade;
4766
}
4867

68+
/**
69+
* Get The Custom Pill Blade (if set)
70+
*/
4971
public function getCustomPillBlade(): ?string
5072
{
5173
return $this->customPillBlade;
5274
}
5375

76+
/**
77+
* Get Custom Reset Button Attributes
78+
*
79+
* @return array<mixed>
80+
*/
5481
public function getCustomResetButtonAttributes(): array
5582
{
56-
return $this->customResetButtonAttributes ?? [];
83+
return $this->customResetButtonAttributes;
5784
}
5885

86+
/**
87+
* Determine of this is an External Livewire Filter
88+
*/
5989
public function getIsAnExternalLivewireFilter(): int
6090
{
61-
return intval($this->isAnExternalLivewireFilter ?? 0);
91+
return intval($this->isAnExternalLivewireFilter);
6292
}
6393

94+
/**
95+
* Get the Separator for Pill Values
96+
*/
6497
public function getSeparator(): string
6598
{
66-
return $this->separator ?? ', ';
99+
return $this->separator;
67100
}
68101

102+
/**
103+
* Determine if Pills should render as HTML
104+
*/
69105
public function shouldUsePillsAsHtml(): int
70106
{
71-
return intval($this->renderPillsAsHtml ?? 0);
107+
return intval($this->renderPillsAsHtml);
72108
}
73109

110+
/**
111+
* Determine if Pill Title should render as HTML
112+
*/
74113
public function shouldUsePillsTitleAsHtml(): int
75114
{
76-
return intval($this->renderPillsTitleAsHtml ?? 0);
115+
return intval($this->renderPillsTitleAsHtml);
77116
}
78117

118+
/**
119+
* Determine if Should watch for Events (i.e. is an External Filter)
120+
*/
79121
public function shouldWatchForEvents(): int
80122
{
81-
return intval($this->watchForEvents ?? 0);
123+
return intval($this->watchForEvents);
82124
}
83125

126+
/**
127+
* Determine if Pill Value is an Array
128+
*/
84129
public function isPillValueAnArray(): bool
85130
{
86131
return ! is_null($this->filterPillValue) && is_array($this->filterPillValue);
87132
}
88133

134+
/**
135+
* Return the separator separated value for the pill
136+
*/
89137
public function getSeparatedPillValue(): ?string
90138
{
91139
if ($this->isPillValueAnArray()) {
@@ -95,6 +143,9 @@ public function getSeparatedPillValue(): ?string
95143
}
96144
}
97145

146+
/**
147+
* Return the safe, separator separated value for the pill
148+
*/
98149
public function getSafeSeparatedPillValue(): ?string
99150
{
100151
$string = $this->getSeparatedPillValue();
@@ -103,11 +154,21 @@ public function getSafeSeparatedPillValue(): ?string
103154

104155
}
105156

157+
/**
158+
* Get the attributes for the Filter Pills Item
159+
*
160+
* @return array<mixed>
161+
*/
106162
public function getFilterPillsItemAttributes(): array
107163
{
108164
return array_merge(['default' => true, 'default-colors' => true, 'default-styling' => true, 'default-text' => true], $this->filterPillsItemAttributes);
109165
}
110166

167+
/**
168+
* Get the Display Data for the Filter Pills
169+
*
170+
* @return array<mixed>
171+
*/
111172
public function getFilterPillDisplayDataArray(): array
112173
{
113174
$array = [];
@@ -118,13 +179,25 @@ public function getFilterPillDisplayDataArray(): array
118179
return $this->getInternalFilterPillDisplayDataArray($array);
119180
}
120181

182+
/**
183+
* Get the Display Data for the Filter Pills
184+
*
185+
* @param array<mixed> $array
186+
* @return array<mixed>
187+
*/
121188
public function getExternalFilterPillDisplayDataArray(array $array = []): array
122189
{
123190
$array[$this->shouldUsePillsAsHtml() ? 'x-html' : 'x-text'] = 'displayString';
124191

125192
return $array;
126193
}
127194

195+
/**
196+
* Get the Display Data for the Filter Pills
197+
*
198+
* @param array<mixed> $array
199+
* @return array<mixed>
200+
*/
128201
public function getInternalFilterPillDisplayDataArray(array $array = []): array
129202
{
130203

@@ -135,20 +208,37 @@ public function getInternalFilterPillDisplayDataArray(array $array = []): array
135208
return $array;
136209
}
137210

211+
/**
212+
* Get the Display Data for the Filter Pills Title
213+
*
214+
* @param array<mixed> $array
215+
* @return array<mixed>
216+
*/
138217
public function getFilterTitleDisplayDataArray(array $array = []): array
139218
{
140219
$array[$this->shouldUsePillsTitleAsHtml() ? 'x-html' : 'x-text'] = 'localFilterTitle';
141220

142221
return $array;
143222
}
144223

224+
/**
225+
* Get the initial setup data
226+
*
227+
* @return array<mixed>
228+
*/
145229
public function getPillSetupData(string $filterKey = '', bool $shouldWatch = false): array
146230
{
147231
$array = array_merge(['filterKey' => $filterKey, 'watchForEvents' => $shouldWatch], $this->toArray());
148232

149233
return $array;
150234
}
151235

236+
/**
237+
* Calculate Any Reset Button Attributes
238+
*
239+
* @param array<mixed> $filterPillsResetFilterButtonAttributes
240+
* @return array<mixed>
241+
*/
152242
public function getCalculatedCustomResetButtonAttributes(string $filterKey, array $filterPillsResetFilterButtonAttributes): array
153243
{
154244
return array_merge(
@@ -165,10 +255,15 @@ public function getCalculatedCustomResetButtonAttributes(string $filterKey, arra
165255
);
166256
}
167257

258+
/**
259+
* Returns the data to an array
260+
*
261+
* @return array<mixed>
262+
*/
168263
public function toArray(): array
169264
{
170265
return [
171-
'filterKey' => $this->filterKey,
266+
'filterKey' => $this->getFilterKey(),
172267
'filterPillTitle' => $this->getTitle(),
173268
'filterPillValue' => $this->getPillValue(),
174269
'isAnExternalLivewireFilter' => $this->getIsAnExternalLivewireFilter(),

src/DataTransferObjects/Filters/StandardFilterPillData.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,43 @@ public static function make(string $filterPillTitle, string $filterSelectName, s
1111
return new self($filterPillTitle, $filterSelectName, $filterPillValue, $renderPillsAsHtml);
1212
}
1313

14+
/**
15+
* Get the Pill Title
16+
*/
1417
public function getTitle(): string
1518
{
1619
return $this->filterPillTitle;
1720
}
1821

22+
/**
23+
* Get the Filter Select Name
24+
*/
1925
public function getSelectName(): string
2026
{
2127
return $this->filterSelectName;
2228
}
2329

30+
/**
31+
* Get The Pill Value
32+
*/
2433
public function getPillValue(): string
2534
{
2635
return $this->filterPillValue;
2736
}
2837

38+
/**
39+
* Should Use Pills as HTML
40+
*/
2941
public function shouldUsePillsAsHtml(): bool
3042
{
31-
return $this->renderPillsAsHtml ?? false;
43+
return $this->renderPillsAsHtml;
3244
}
3345

46+
/**
47+
* Returns the data to an array
48+
*
49+
* @return array<mixed>
50+
*/
3451
public function toArray(): array
3552
{
3653
return [

src/Views/Columns/Traits/HasFooter.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,19 @@ public function getFooterCallback()
5353

5454
public function footerCallbackIsString(): bool
5555
{
56+
if (! $this->hasFooterCallback()) {
57+
return false;
58+
}
59+
5660
return is_string($this->getFooterCallback());
5761
}
5862

5963
public function footerCallbackIsFilter(): bool
6064
{
65+
if (! $this->hasFooterCallback()) {
66+
return false;
67+
}
68+
6169
$callback = $this->getFooterCallback();
6270

6371
return $callback instanceof Filter;
@@ -66,9 +74,10 @@ public function footerCallbackIsFilter(): bool
6674
public function getFooterContents(mixed $rows, array $filterGenericData): \Illuminate\Contracts\Foundation\Application|\Illuminate\View\Factory|\Illuminate\View\View|string|HtmlString
6775
{
6876
$value = null;
69-
$callback = $this->getFooterCallback();
70-
7177
if ($this->hasFooterCallback()) {
78+
79+
$callback = $this->getFooterCallback();
80+
7281
if (is_callable($callback)) {
7382
$value = call_user_func($callback, $rows);
7483

@@ -111,7 +120,7 @@ public function getNewFooterContents(mixed $rows): string|HtmlString
111120

112121
public function getFooterFilter(?Filter $filter, array $filterGenericData): \Illuminate\Contracts\Foundation\Application|\Illuminate\View\Factory|\Illuminate\View\View|string
113122
{
114-
if ($filter !== null && $filter instanceof Filter) {
123+
if ($filter !== null) {
115124
return $filter->setFilterPosition('footer')->setGenericDisplayData($filterGenericData)->render();
116125
} else {
117126
throw new DataTableConfigurationException('The footer callback must be a closure, filter object, or filter key if using footerFilter().');

0 commit comments

Comments
 (0)