Skip to content

Commit 3041739

Browse files
committed
Clean up code
1 parent 1c4ef53 commit 3041739

File tree

3 files changed

+34
-38
lines changed

3 files changed

+34
-38
lines changed

src/FilamentDeveloperLoginsServiceProvider.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use DutchCodingCompany\FilamentDeveloperLogins\Livewire\MenuLogins;
66
use DutchCodingCompany\FilamentDeveloperLogins\View\Components\DeveloperLogins;
7-
use Filament\Panel;
87
use Filament\Facades\Filament;
8+
use Filament\Panel;
99
use Filament\Support\Concerns\EvaluatesClosures;
1010
use Filament\Support\Facades\FilamentView;
1111
use Filament\View\PanelsRenderHook;
@@ -45,20 +45,17 @@ public function packageBooted(): void
4545

4646
protected static function registerRenderHooks(): void
4747
{
48-
$panel = Filament::getCurrentPanel();
49-
50-
if(! self::enabledForPanel($panel)) {
51-
return;
52-
}
53-
54-
/** @var FilamentDeveloperLoginsPlugin $plugin */
55-
$plugin = $panel->getPlugin('filament-developer-logins');
56-
5748
FilamentView::registerRenderHook(
5849
PanelsRenderHook::AUTH_LOGIN_FORM_AFTER,
59-
static function () use ($plugin) : ?string {
50+
static function (): ?string {
51+
$panel = Filament::getCurrentPanel();
52+
if (! self::panelHasPlugin($panel)) {
53+
return null;
54+
}
6055

61-
if (! $plugin->getEnabled() || ! self::enabledForPanel(Filament::getCurrentPanel())) {
56+
/** @var FilamentDeveloperLoginsPlugin $plugin */
57+
$plugin = $panel->getPlugin('filament-developer-logins');
58+
if (! $plugin->getEnabled()) {
6259
return null;
6360
}
6461

@@ -68,8 +65,15 @@ static function () use ($plugin) : ?string {
6865

6966
FilamentView::registerRenderHook(
7067
PanelsRenderHook::GLOBAL_SEARCH_AFTER,
71-
static function () use ($plugin) : ?string {
72-
if (! $plugin->getEnabled() || ! $plugin->getSwitchable() || ! self::enabledForPanel(Filament::getCurrentPanel())) {
68+
static function (): ?string {
69+
$panel = Filament::getCurrentPanel();
70+
if (! self::panelHasPlugin($panel)) {
71+
return null;
72+
}
73+
74+
/** @var FilamentDeveloperLoginsPlugin $plugin */
75+
$plugin = $panel->getPlugin('filament-developer-logins');
76+
if (! $plugin->getEnabled() || ! $plugin->getSwitchable()) {
7377
return null;
7478
}
7579

@@ -78,7 +82,7 @@ static function () use ($plugin) : ?string {
7882
);
7983
}
8084

81-
protected static function enabledForPanel(?Panel $panel)
85+
protected static function panelHasPlugin(?Panel $panel): bool
8286
{
8387
return ! is_null($panel) && $panel->hasPlugin('filament-developer-logins');
8488
}

tests/Feature/MenuLoginsTest.php

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,16 @@ public function test_forbidden_is_returned_when_enabled_or_switchable_is_false()
8484

8585
public function test_component_is_only_rendered_in_panel_with_plugin(): void
8686
{
87-
8887
$user = TestUser::factory()->create();
8988

9089
$this->actingAs($user)
9190
->get(Dashboard::getUrl(panel: $this->panelName))
9291
->assertSuccessful()
9392
->assertSeeLivewire(MenuLogins::class);
9493

95-
9694
$this->actingAs($user)
97-
->get(Dashboard::getUrl(panel: $this->panelName . '-other' ))
95+
->get(Dashboard::getUrl(panel: $this->panelName.'-other'))
9896
->assertSuccessful()
9997
->assertDontSeeLivewire(MenuLogins::class);
10098
}
101-
102-
protected function registerTestPanel(): void
103-
{
104-
parent::registerTestPanel();
105-
Filament::registerPanel(fn() => Panel::make()
106-
->darkMode(false)
107-
->id($this->panelName . '-other')
108-
->path($this->panelName . '-other')
109-
->login()
110-
->pages([
111-
Dashboard::class,
112-
])
113-
->plugins([
114-
]),
115-
);
116-
}
117-
118-
11999
}

tests/TestCase.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ protected function setUp(): void
3636
);
3737
}
3838

39-
protected function registerTestPanel(): void
39+
protected function registerTestPanels(): void
4040
{
4141
Filament::registerPanel(
4242
fn (): Panel => Panel::make()
@@ -57,6 +57,18 @@ protected function registerTestPanel(): void
5757
->modelClass(TestUser::class),
5858
]),
5959
);
60+
61+
Filament::registerPanel(fn () => Panel::make()
62+
->darkMode(false)
63+
->id($this->panelName.'-other')
64+
->path($this->panelName.'-other')
65+
->login()
66+
->pages([
67+
Dashboard::class,
68+
])
69+
->plugins([
70+
]),
71+
);
6072
}
6173

6274
protected function defineRoutes($router): void
@@ -80,7 +92,7 @@ protected function getEnvironmentSetUp($app): void
8092

8193
protected function getPackageProviders($app): array
8294
{
83-
$this->registerTestPanel();
95+
$this->registerTestPanels();
8496

8597
return [
8698
FilamentServiceProvider::class,

0 commit comments

Comments
 (0)