Skip to content

Commit 0d2e0d1

Browse files
authored
Merge pull request #48 from awcodes/fix/format-types
Fix: format types in widget class
2 parents f89b239 + 51ef883 commit 0d2e0d1

File tree

5 files changed

+49
-43
lines changed

5 files changed

+49
-43
lines changed

src/Concerns/HandlesOverlookWidgetCustomization.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Awcodes\Overlook\Concerns;
46

57
use Illuminate\Database\Eloquent\Builder;

src/Contracts/CustomizeOverlookWidget.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Awcodes\Overlook\Contracts;
46

57
use Illuminate\Database\Eloquent\Builder;

src/OverlookPlugin.php

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Awcodes\Overlook;
46

57
use Closure;
@@ -9,63 +11,59 @@
911
use Filament\Panel;
1012
use Filament\Support\Concerns\EvaluatesClosures;
1113

12-
class OverlookPlugin implements Plugin
14+
final class OverlookPlugin implements Plugin
1315
{
1416
use EvaluatesClosures;
1517
use HasColumns;
1618

17-
protected array | Closure | null $excludes = null;
19+
protected array|Closure|null $excludes = null;
1820

19-
protected array | Closure | null $includes = null;
21+
protected array|Closure|null $includes = null;
2022

21-
protected bool | Closure | null $shouldAbbreviateCount = null;
23+
protected bool|Closure|null $shouldAbbreviateCount = null;
2224

23-
protected bool | Closure | null $shouldShowTooltips = null;
25+
protected bool|Closure|null $shouldShowTooltips = null;
2426

25-
protected int | Closure | null $shouldSortAlphabetical = null;
27+
protected int|Closure|null $shouldSortAlphabetical = null;
2628

27-
protected int | Closure | null $sort = null;
29+
protected int|Closure|null $sort = null;
2830

29-
protected array | Closure | null $icons = null;
31+
protected array|Closure|null $icons = null;
3032

31-
public function getId(): string
33+
public static function make(): static
3234
{
33-
return 'awcodes/overlook';
35+
return app(self::class);
3436
}
3537

36-
public function register(Panel $panel): void
38+
public static function get(): static
3739
{
40+
return filament(app(static::class)->getId());
3841
}
3942

40-
public function boot(Panel $panel): void
43+
public function getId(): string
4144
{
45+
return 'awcodes/overlook';
4246
}
4347

44-
public static function make(): static
45-
{
46-
return app(static::class);
47-
}
48+
public function register(Panel $panel): void {}
4849

49-
public static function get(): static
50-
{
51-
return filament(app(static::class)->getId());
52-
}
50+
public function boot(Panel $panel): void {}
5351

54-
public function alphabetical(bool | Closure | null $condition = true): static
52+
public function alphabetical(bool|Closure|null $condition = true): static
5553
{
5654
$this->shouldSortAlphabetical = $condition;
5755

5856
return $this;
5957
}
6058

61-
public function abbreviateCount(bool | Closure | null $condition = true): static
59+
public function abbreviateCount(bool|Closure|null $condition = true): static
6260
{
6361
$this->shouldAbbreviateCount = $condition;
6462

6563
return $this;
6664
}
6765

68-
public function excludes(array | Closure $resources): static
66+
public function excludes(array|Closure $resources): static
6967
{
7068
$this->excludes = $resources;
7169

@@ -103,7 +101,7 @@ public function getSort(): int
103101
return $this->evaluate($this->sort) ?? -1;
104102
}
105103

106-
public function includes(array | Closure $resources): static
104+
public function includes(array|Closure $resources): static
107105
{
108106
$this->includes = $resources;
109107

@@ -125,21 +123,21 @@ public function shouldSortAlphabetical(): bool
125123
return $this->evaluate($this->shouldSortAlphabetical) ?? false;
126124
}
127125

128-
public function sort(int | Closure $sort): static
126+
public function sort(int|Closure $sort): static
129127
{
130128
$this->sort = $sort;
131129

132130
return $this;
133131
}
134132

135-
public function tooltips(bool | Closure | null $condition = true): static
133+
public function tooltips(bool|Closure|null $condition = true): static
136134
{
137135
$this->shouldShowTooltips = $condition;
138136

139137
return $this;
140138
}
141139

142-
public function icons(array | Closure | null $icons): static
140+
public function icons(array|Closure|null $icons): static
143141
{
144142
$this->icons = $icons;
145143

src/OverlookServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Awcodes\Overlook;
46

57
use Livewire\Livewire;
68
use Spatie\LaravelPackageTools\Package;
79
use Spatie\LaravelPackageTools\PackageServiceProvider;
810

9-
class OverlookServiceProvider extends PackageServiceProvider
11+
final class OverlookServiceProvider extends PackageServiceProvider
1012
{
1113
public function configurePackage(Package $package): void
1214
{

src/Widgets/OverlookWidget.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Awcodes\Overlook\Widgets;
46

57
use Awcodes\Overlook\Contracts\CustomizeOverlookWidget;
@@ -8,12 +10,8 @@
810
use Filament\Widgets\Widget;
911
use NumberFormatter;
1012

11-
class OverlookWidget extends Widget
13+
final class OverlookWidget extends Widget
1214
{
13-
protected static string $view = 'overlook::widget';
14-
15-
protected int | string | array $columnSpan = 'full';
16-
1715
public array $data = [];
1816

1917
public array $excludes = [];
@@ -24,6 +22,15 @@ class OverlookWidget extends Widget
2422

2523
public array $icons = [];
2624

25+
protected static string $view = 'overlook::widget';
26+
27+
protected int|string|array $columnSpan = 'full';
28+
29+
public static function getSort(): int
30+
{
31+
return OverlookPlugin::get()->getSort();
32+
}
33+
2734
/**
2835
* @throws Exception
2936
*/
@@ -36,23 +43,23 @@ public function mount(): void
3643
}
3744
}
3845

39-
public function convertCount(string $number): string
46+
public function convertCount(string | int | float $number): string
4047
{
4148
if (OverlookPlugin::get()->shouldAbbreviateCount()) {
4249
$formatter = new NumberFormatter(
4350
app()->getLocale(),
4451
NumberFormatter::PATTERN_DECIMAL,
4552
);
4653

47-
return $formatter->format($number);
54+
return $formatter->format((int) $number);
4855
}
4956

5057
return $number;
5158
}
5259

53-
public function formatRawCount(string $number): string
60+
public function formatRawCount(string | int | float $number): string
5461
{
55-
return number_format($number);
62+
return number_format((int) $number);
5663
}
5764

5865
/**
@@ -105,15 +112,10 @@ public function getData(): array
105112
->toArray();
106113
}
107114

108-
public static function getSort(): int
109-
{
110-
return OverlookPlugin::get()->getSort();
111-
}
112-
113115
public function shouldShowTooltips(string $number): bool
114116
{
115117
$plugin = OverlookPlugin::get();
116118

117-
return strlen($number) >= 4 && $plugin->shouldAbbreviateCount() && $plugin->shouldShowTooltips();
119+
return mb_strlen($number) >= 4 && $plugin->shouldAbbreviateCount() && $plugin->shouldShowTooltips();
118120
}
119121
}

0 commit comments

Comments
 (0)