From b181914335d343a7284b84149fc96b4ff6d0f9af Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Sun, 13 Apr 2025 10:05:44 +0100 Subject: [PATCH 1/8] feat: add abstract alert --- tests/Unit/Foundation/AbstractAlert.php | 149 ++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 tests/Unit/Foundation/AbstractAlert.php diff --git a/tests/Unit/Foundation/AbstractAlert.php b/tests/Unit/Foundation/AbstractAlert.php new file mode 100644 index 00000000..1ef89061 --- /dev/null +++ b/tests/Unit/Foundation/AbstractAlert.php @@ -0,0 +1,149 @@ +id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + expect($alert->getId())->not()->toBeEmpty() + ->and($alert->getIdTag())->toContain('test_alert'); +})->group('alert', 'abstract-alert', 'auto-set-id'); + +it('can manually set ID', function () { + $alert = new class extends AbstractAlert { + public string $message = 'Test Alert'; + public function key(): string + { + return 'manual_alert'; + } + + public static function fill(array $alert): AlertInterface + { + $instance = new self(); + $instance->id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + $alert->id('custom-id'); + + expect($alert->getId())->toBe('custom-id') + ->and($alert->getIdTag())->toBe('manual_alert.custom-id'); +})->group('alert', 'abstract-alert', 'manual-set-id'); + +it('flashes alert to session if id and message are set', function () { + $alert = new class extends AbstractAlert { + public string $message = 'Hello session'; + public function key(): string + { + return 'session_alert'; + } + + public static function fill(array $alert): AlertInterface + { + $instance = new self(); + $instance->id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + $alert->id('flash-id'); + $sessionKey = SessionKey::key('session_alert', 'session_alert.flash-id'); + + expect(Session::get($sessionKey))->toBe($alert); +})->group('alert', 'abstract-alert', 'flash-session'); + +it('does not flash if message is empty', function () { + $alert = new class extends AbstractAlert { + public function key(): string + { + return 'session_alert'; + } + + public static function fill(array $alert): AlertInterface + { + $instance = new self(); + $instance->id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + $alert->id('no-message-id'); + $sessionKey = SessionKey::key('session_alert', 'session_alert.no-message-id'); + + expect(Session::has($sessionKey))->toBeFalse(); +})->group('alert', 'abstract-alert', 'no-flash-empty-message'); + +it('can forget session key', function () { + $alert = new class extends AbstractAlert { + public string $message = 'Forget me'; + public function key(): string + { + return 'forget_alert'; + } + + public static function fill(array $alert): AlertInterface + { + $instance = new self(); + $instance->id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + $alert->id('forget-id'); + $sessionKey = SessionKey::key('forget_alert', 'forget_alert.forget-id'); + + expect(Session::get($sessionKey))->toBe($alert); + + $alert->forget(); + + expect(Session::has($sessionKey))->toBeFalse(); +})->group('alert', 'abstract-alert', 'forget-session'); + +it('can convert to array and json', function () { + $alert = new class extends AbstractAlert { + public string $message = 'Format test'; + public function key(): string + { + return 'json_alert'; + } + + public static function fill(array $alert): AlertInterface + { + $instance = new self(); + $instance->id($alert['id'] ?? 'default-id'); + $instance->message = $alert['message'] ?? 'Default message'; + return $instance; + } + }; + + $id = $alert->getId(); + + expect($alert->toArray())->toBe(['id' => $id]) + ->and($alert->toJson())->toBe(json_encode(['id' => $id])); +})->group('alert', 'abstract-alert', 'to-array-json'); From 53f45d57a5ae7bf30698f03c963140498708a3e5 Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Sun, 13 Apr 2025 10:12:00 +0100 Subject: [PATCH 2/8] feat: add abstract alert test --- ...bstractAlert.php => AbstractAlertTest.php} | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) rename tests/Unit/Foundation/{AbstractAlert.php => AbstractAlertTest.php} (83%) diff --git a/tests/Unit/Foundation/AbstractAlert.php b/tests/Unit/Foundation/AbstractAlertTest.php similarity index 83% rename from tests/Unit/Foundation/AbstractAlert.php rename to tests/Unit/Foundation/AbstractAlertTest.php index 1ef89061..16a22e7b 100644 --- a/tests/Unit/Foundation/AbstractAlert.php +++ b/tests/Unit/Foundation/AbstractAlertTest.php @@ -12,11 +12,17 @@ it('can auto-set and retrieve ID', function () { $alert = new class extends AbstractAlert { public string $message = 'Test Alert'; + public function key(): string { return 'test_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); @@ -33,11 +39,17 @@ public static function fill(array $alert): AlertInterface it('can manually set ID', function () { $alert = new class extends AbstractAlert { public string $message = 'Test Alert'; + public function key(): string { return 'manual_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); @@ -50,17 +62,23 @@ public static function fill(array $alert): AlertInterface $alert->id('custom-id'); expect($alert->getId())->toBe('custom-id') - ->and($alert->getIdTag())->toBe('manual_alert.custom-id'); + ->and($alert->getIdTag())->toBe('alert.custom-id'); })->group('alert', 'abstract-alert', 'manual-set-id'); it('flashes alert to session if id and message are set', function () { $alert = new class extends AbstractAlert { public string $message = 'Hello session'; + public function key(): string { return 'session_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); @@ -71,7 +89,7 @@ public static function fill(array $alert): AlertInterface }; $alert->id('flash-id'); - $sessionKey = SessionKey::key('session_alert', 'session_alert.flash-id'); + $sessionKey = SessionKey::key('session_alert', 'alert.flash-id'); expect(Session::get($sessionKey))->toBe($alert); })->group('alert', 'abstract-alert', 'flash-session'); @@ -83,17 +101,22 @@ public function key(): string return 'session_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); - $instance->message = $alert['message'] ?? 'Default message'; + $instance->message = $alert['message'] ?? ''; return $instance; } }; $alert->id('no-message-id'); - $sessionKey = SessionKey::key('session_alert', 'session_alert.no-message-id'); + $sessionKey = SessionKey::key('session_alert', 'alert.no-message-id'); expect(Session::has($sessionKey))->toBeFalse(); })->group('alert', 'abstract-alert', 'no-flash-empty-message'); @@ -101,11 +124,17 @@ public static function fill(array $alert): AlertInterface it('can forget session key', function () { $alert = new class extends AbstractAlert { public string $message = 'Forget me'; + public function key(): string { return 'forget_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); @@ -116,7 +145,7 @@ public static function fill(array $alert): AlertInterface }; $alert->id('forget-id'); - $sessionKey = SessionKey::key('forget_alert', 'forget_alert.forget-id'); + $sessionKey = SessionKey::key('forget_alert', 'alert.forget-id'); expect(Session::get($sessionKey))->toBe($alert); @@ -128,11 +157,17 @@ public static function fill(array $alert): AlertInterface it('can convert to array and json', function () { $alert = new class extends AbstractAlert { public string $message = 'Format test'; + public function key(): string { return 'json_alert'; } + public function getTag(): string + { + return 'alert'; + } + public static function fill(array $alert): AlertInterface { $instance = new self(); From 319f758a71863b514e6e344c8baa0b02ece7d001 Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Sun, 13 Apr 2025 11:19:41 +0100 Subject: [PATCH 3/8] feat: add alert factory test --- tests/Unit/Factory/AlertFactoryTest.php | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 tests/Unit/Factory/AlertFactoryTest.php diff --git a/tests/Unit/Factory/AlertFactoryTest.php b/tests/Unit/Factory/AlertFactoryTest.php new file mode 100644 index 00000000..76e31e5f --- /dev/null +++ b/tests/Unit/Factory/AlertFactoryTest.php @@ -0,0 +1,28 @@ +toBeInstanceOf(AlertInterface::class) + ->and($alert->getMessage()) + ->toBe('Hello World'); +})->group('unit', 'factory', 'alert-factory'); + + +it('creates an alert using makeFromArray()', function () { + $alert = AlertFactory::makeFromArray([ + 'id' => 1, + 'title' => 'Test Alert', + 'level' => 'info', + 'tag' => 'default', + 'type' => 'message', + 'message' => 'Hello World', + ]); + + expect($alert)->toBeInstanceOf(AlertInterface::class) + ->and($alert->getMessage()) + ->toBe('Hello World'); +})->group('unit', 'factory', 'alert-factory'); \ No newline at end of file From 631a3c31030294dafcdbe1a76c20d63c1c0eb901 Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Tue, 15 Apr 2025 22:05:32 +0100 Subject: [PATCH 4/8] feat: toastr classic --- .../components/toastr-classic.blade.php | 73 ++++++++++++++++++ .../Tailwind/Components/ToastrClassic.php | 75 +++++++++++++++++++ 2 files changed, 148 insertions(+) create mode 100644 resources/views/themes/tailwind/components/toastr-classic.blade.php create mode 100644 src/Themes/Tailwind/Components/ToastrClassic.php diff --git a/resources/views/themes/tailwind/components/toastr-classic.blade.php b/resources/views/themes/tailwind/components/toastr-classic.blade.php new file mode 100644 index 00000000..41a28ca3 --- /dev/null +++ b/resources/views/themes/tailwind/components/toastr-classic.blade.php @@ -0,0 +1,73 @@ +
+
+ +
+
diff --git a/src/Themes/Tailwind/Components/ToastrClassic.php b/src/Themes/Tailwind/Components/ToastrClassic.php new file mode 100644 index 00000000..ee02fa17 --- /dev/null +++ b/src/Themes/Tailwind/Components/ToastrClassic.php @@ -0,0 +1,75 @@ +alerts = $alerts + ->filter(function ($alert) { + return $alert->getTag() === $this->tag; + }) + ->values() + ->map(function ($alert) { + $alert->forget(); + return $alert->toArray(); + })->toArray(); + } + + /** + * Create a new component instance. + * + * @throws Exception + */ + public function mount(): void + { + $this->resolve($this->tag); + } + + #[On('refresh-alert-toastr')] + public function refresh(string $tag, array $alerts): void + { + if ($tag !== $this->tag) { + return; + } + + $this->resolve($tag, array_values($alerts)); + $this->dispatch('open-alert-toastr'); + } + + /** + * Get the view / contents that represent the component. + */ + public function render(): View + { + return view('alert::themes.tailwind.components.toastr'); + } +} From 04d0e098435d18d1087b4e3b584089977989f9ac Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Tue, 15 Apr 2025 22:28:48 +0100 Subject: [PATCH 5/8] feat: toastr classic --- resources/css/themes/tailwind/alert.css | 8 ++ .../themes/tailwind/components/position.css | 8 ++ resources/scss/themes/tailwind/alert.css | 8 ++ resources/scss/themes/tailwind/alert.css.map | 2 +- .../themes/tailwind/components/position.scss | 1 + .../tailwind/components/notify.blade.php | 4 +- src/Types/ToastrClassic.php | 113 ++++++++++++++++++ 7 files changed, 142 insertions(+), 2 deletions(-) create mode 100644 src/Types/ToastrClassic.php diff --git a/resources/css/themes/tailwind/alert.css b/resources/css/themes/tailwind/alert.css index 13f633eb..f71dbbd0 100644 --- a/resources/css/themes/tailwind/alert.css +++ b/resources/css/themes/tailwind/alert.css @@ -34,34 +34,42 @@ @apply inline-flex items-center justify-center h-10 px-4 py-2 text-sm font-medium text-blue-600 transition-colors rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 hover:underline; } +.alert-position, .alert-toastr-position { @apply fixed px-2 mt-3 overflow-x-hidden z-50; } +.alert-position.top-right, .alert-toastr-position.top-right { @apply top-0 right-0; } +.alert-position.top-left, .alert-toastr-position.top-left { @apply top-0 left-0; } +.alert-position.bottom-right, .alert-toastr-position.bottom-right { @apply bottom-0 right-0; } +.alert-position.bottom-left, .alert-toastr-position.bottom-left { @apply bottom-0 left-0; } +.alert-position.top-center, .alert-toastr-position.top-center { @apply top-0 left-1/2 transform -translate-x-1/2; } +.alert-position.bottom-center, .alert-toastr-position.bottom-center { @apply bottom-0 left-1/2 transform -translate-x-1/2; } +.alert-position.center, .alert-toastr-position.center { @apply top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2; } diff --git a/resources/css/themes/tailwind/components/position.css b/resources/css/themes/tailwind/components/position.css index 269b9d2f..2bab0385 100644 --- a/resources/css/themes/tailwind/components/position.css +++ b/resources/css/themes/tailwind/components/position.css @@ -1,24 +1,32 @@ +.alert-position, .alert-toastr-position { @apply fixed px-2 mt-3 overflow-x-hidden z-50; } +.alert-position.top-right, .alert-toastr-position.top-right { @apply top-0 right-0; } +.alert-position.top-left, .alert-toastr-position.top-left { @apply top-0 left-0; } +.alert-position.bottom-right, .alert-toastr-position.bottom-right { @apply bottom-0 right-0; } +.alert-position.bottom-left, .alert-toastr-position.bottom-left { @apply bottom-0 left-0; } +.alert-position.top-center, .alert-toastr-position.top-center { @apply top-0 left-1/2 transform -translate-x-1/2; } +.alert-position.bottom-center, .alert-toastr-position.bottom-center { @apply bottom-0 left-1/2 transform -translate-x-1/2; } +.alert-position.center, .alert-toastr-position.center { @apply top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2; } diff --git a/resources/scss/themes/tailwind/alert.css b/resources/scss/themes/tailwind/alert.css index 7e39120e..2d88747c 100644 --- a/resources/scss/themes/tailwind/alert.css +++ b/resources/scss/themes/tailwind/alert.css @@ -26,27 +26,35 @@ @apply inline-flex items-center justify-center h-10 px-4 py-2 text-sm font-medium text-blue-600 transition-colors rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 hover:underline; } +.alert-position, .alert-toastr-position { @apply fixed px-2 mt-3 overflow-x-hidden z-50; } +.alert-position.top-right, .alert-toastr-position.top-right { @apply top-0 right-0; } +.alert-position.top-left, .alert-toastr-position.top-left { @apply top-0 left-0; } +.alert-position.bottom-right, .alert-toastr-position.bottom-right { @apply bottom-0 right-0; } +.alert-position.bottom-left, .alert-toastr-position.bottom-left { @apply bottom-0 left-0; } +.alert-position.top-center, .alert-toastr-position.top-center { @apply top-0 left-1/2 transform -translate-x-1/2; } +.alert-position.bottom-center, .alert-toastr-position.bottom-center { @apply bottom-0 left-1/2 transform -translate-x-1/2; } +.alert-position.center, .alert-toastr-position.center { @apply top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2; } diff --git a/resources/scss/themes/tailwind/alert.css.map b/resources/scss/themes/tailwind/alert.css.map index 331fc271..85bb3126 100644 --- a/resources/scss/themes/tailwind/alert.css.map +++ b/resources/scss/themes/tailwind/alert.css.map @@ -1 +1 @@ -{"version":3,"sourceRoot":"","sources":["components/button.scss","components/position.scss","components/field.scss","components/message.scss","components/toastr.scss","components/notify.scss","components/modal.scss"],"names":[],"mappings":"AACI;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;;AClCR;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;;AC3BF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;;ACdJ;EAEE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAEA;EACI;;AAIN;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;;AC5DN;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;IAAO;;EACP;IAAK;;;AAGP;EACE;;;ACrDJ;EACE;;AAEA;EACE;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;;AAGF;EAEE;;AAGF;EAEE;;AAEA;EACE;;AAGF;EACE;;AAIJ;EACE;IAAO;;EACP;IAAK;;;AAGP;EACE;EACA;;;ACpEJ;EACE;;AAEA;EACE;;AAGF;EACE;;AAEA;EAAU;;AACV;EAAW;;AACX;EAAU;;AACV;EAAgB;;AAChB;EAAe;;AACf;EAAe;;AAGjB;EACE;;AAEA;EAAiB;;AACjB;EAAe;;AACf;EAAiB;;AACjB;EAAc;;AAEd;EACE;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE","file":"alert.css"} \ No newline at end of file +{"version":3,"sourceRoot":"","sources":["components/button.scss","components/position.scss","components/field.scss","components/message.scss","components/toastr.scss","components/notify.scss","components/modal.scss"],"names":[],"mappings":"AACI;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;AAGJ;EACI;;;AClCR;AAAA;EAEE;;AAEA;AAAA;EACE;;AAGF;AAAA;EACE;;AAGF;AAAA;EACE;;AAGF;AAAA;EACE;;AAGF;AAAA;EACE;;AAGF;AAAA;EACE;;AAGF;AAAA;EACE;;;AC5BF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;;ACdJ;EAEE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAEA;EACI;;AAIN;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;;AC5DN;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;IAAO;;EACP;IAAK;;;AAGP;EACE;;;ACrDJ;EACE;;AAEA;EACE;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;;AAGF;EAEE;;AAGF;EAEE;;AAEA;EACE;;AAGF;EACE;;AAIJ;EACE;IAAO;;EACP;IAAK;;;AAGP;EACE;EACA;;;ACpEJ;EACE;;AAEA;EACE;;AAGF;EACE;;AAEA;EAAU;;AACV;EAAW;;AACX;EAAU;;AACV;EAAgB;;AAChB;EAAe;;AACf;EAAe;;AAGjB;EACE;;AAEA;EAAiB;;AACjB;EAAe;;AACf;EAAiB;;AACjB;EAAc;;AAEd;EACE;;AAGF;EACE;;AAGF;EACE;;AAIJ;EACE;;AAGF;EACE;;AAEA;EACE;;AAGF;EACE","file":"alert.css"} \ No newline at end of file diff --git a/resources/scss/themes/tailwind/components/position.scss b/resources/scss/themes/tailwind/components/position.scss index 3ae5a982..68338054 100644 --- a/resources/scss/themes/tailwind/components/position.scss +++ b/resources/scss/themes/tailwind/components/position.scss @@ -1,3 +1,4 @@ +.alert-position, .alert-toastr-position { @apply fixed px-2 mt-3 overflow-x-hidden z-50; diff --git a/resources/views/themes/tailwind/components/notify.blade.php b/resources/views/themes/tailwind/components/notify.blade.php index 8055a8ec..63ea0a85 100644 --- a/resources/views/themes/tailwind/components/notify.blade.php +++ b/resources/views/themes/tailwind/components/notify.blade.php @@ -1,7 +1,9 @@
forget($tag); }); } -} \ No newline at end of file +} diff --git a/src/Contracts/LivewireInterface.php b/src/Contracts/LivewireInterface.php index caffe3a1..d77c5df6 100644 --- a/src/Contracts/LivewireInterface.php +++ b/src/Contracts/LivewireInterface.php @@ -2,8 +2,6 @@ namespace Digitlimit\Alert\Contracts; -use Illuminate\Support\Collection; - interface LivewireInterface { public function refresh(string $tag, array $alerts): void; diff --git a/src/Contracts/ThemeInterface.php b/src/Contracts/ThemeInterface.php index 6b58dad2..2ce878bf 100644 --- a/src/Contracts/ThemeInterface.php +++ b/src/Contracts/ThemeInterface.php @@ -8,5 +8,4 @@ interface ThemeInterface * Alert types. */ public static function types(): array; - } diff --git a/src/Foundation/AbstractAlert.php b/src/Foundation/AbstractAlert.php index 2143dcc5..7f76ccc8 100644 --- a/src/Foundation/AbstractAlert.php +++ b/src/Foundation/AbstractAlert.php @@ -5,14 +5,14 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Helpers\Helper; use Digitlimit\Alert\Helpers\SessionKey; -use Illuminate\Support\Facades\Session; -use Illuminate\Contracts\Support\Jsonable; use Illuminate\Contracts\Support\Arrayable; +use Illuminate\Contracts\Support\Jsonable; +use Illuminate\Support\Facades\Session; /** * @property string $message */ -abstract class AbstractAlert implements AlertInterface, Jsonable, Arrayable +abstract class AbstractAlert implements AlertInterface, Arrayable, Jsonable { /** * Alert unique ID. @@ -35,7 +35,7 @@ public function __construct() */ public function id(string|int $id): self { - if (!empty($this->id) && $this->id !== $id) { + if (! empty($this->id) && $this->id !== $id) { $this->forget(); } @@ -72,7 +72,7 @@ public function getId(): string|int */ public function getIdTag(): string { - return $this->getTag() . '.' . $this->getId(); + return $this->getTag().'.'.$this->getId(); } /** @@ -103,7 +103,7 @@ public function flash(): void public function forget(?string $tag = null): self { $tag = $tag - ? $tag . '.' . $this->getId() + ? $tag.'.'.$this->getId() : $this->getIdTag(); $sessionKey = SessionKey::key($this->key(), $tag); diff --git a/src/Helpers.php b/src/Helpers.php index 0e09601c..9bae65ff 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -1,14 +1,15 @@ message($message); @@ -21,13 +22,15 @@ function alert(string $message, ?string $title = null): Message { } if (! function_exists('field')) { - function field(string $name, string $message): Field { + function field(string $name, string $message): Field + { return app('alert')->field($name, $message); } } if (! function_exists('modal')) { - function modal(string $message, ?string $title = null,): Modal { + function modal(string $message, ?string $title = null): Modal + { $alert = app('alert')->modal($message); if ($title) { @@ -39,7 +42,8 @@ function modal(string $message, ?string $title = null,): Modal { } if (! function_exists('toastr')) { - function toastr(string $message, ?string $title = null,): Toastr { + function toastr(string $message, ?string $title = null): Toastr + { $alert = app('alert')->toastr($message); if ($title) { @@ -51,7 +55,8 @@ function toastr(string $message, ?string $title = null,): Toastr { } if (! function_exists('notify')) { - function notify(string $message, ?string $title = null,): Notify { + function notify(string $message, ?string $title = null): Notify + { $alert = app('alert')->notify($message); if ($title) { @@ -63,7 +68,8 @@ function notify(string $message, ?string $title = null,): Notify { } if (! function_exists('forgetAlert')) { - function forgetAlert(string $type, string $tag = Alert::DEFAULT_TAG): void { + function forgetAlert(string $type, string $tag = Alert::DEFAULT_TAG): void + { app('alert')->forget($type, $tag); } } diff --git a/src/Helpers/Type.php b/src/Helpers/Type.php index efeb57e8..f4dd74fc 100644 --- a/src/Helpers/Type.php +++ b/src/Helpers/Type.php @@ -63,4 +63,4 @@ public static function classname(string $type): string return self::type($type)['alert']; } -} \ No newline at end of file +} diff --git a/src/Icons/Error.php b/src/Icons/Error.php index 628bcf78..bdd5f296 100644 --- a/src/Icons/Error.php +++ b/src/Icons/Error.php @@ -15,8 +15,6 @@ class Error extends Component /** * Check if the alert icon is circled. - * - * @return bool */ public function isCircled(): bool { diff --git a/src/Icons/Info.php b/src/Icons/Info.php index 60068ae9..1a94c868 100644 --- a/src/Icons/Info.php +++ b/src/Icons/Info.php @@ -15,8 +15,6 @@ class Info extends Component /** * Check if the alert icon is circled. - * - * @return bool */ public function isCircled(): bool { diff --git a/src/Icons/Success.php b/src/Icons/Success.php index 77b44a52..f813ea33 100644 --- a/src/Icons/Success.php +++ b/src/Icons/Success.php @@ -15,8 +15,6 @@ class Success extends Component /** * Check if the alert icon is circled. - * - * @return bool */ public function isCircled(): bool { diff --git a/src/Icons/Warning.php b/src/Icons/Warning.php index 3bad66f4..2bff5c28 100644 --- a/src/Icons/Warning.php +++ b/src/Icons/Warning.php @@ -15,8 +15,6 @@ class Warning extends Component /** * Check if the alert icon is circled. - * - * @return bool */ public function isCircled(): bool { diff --git a/src/Themes/Tailwind/AbstractComponent.php b/src/Themes/Tailwind/AbstractComponent.php index 42343259..01ea93f2 100644 --- a/src/Themes/Tailwind/AbstractComponent.php +++ b/src/Themes/Tailwind/AbstractComponent.php @@ -4,7 +4,4 @@ use Livewire\Component; -abstract class AbstractComponent extends Component -{ - -} +abstract class AbstractComponent extends Component {} diff --git a/src/Themes/Tailwind/Components/Field.php b/src/Themes/Tailwind/Components/Field.php index 9fa7c04d..84495a71 100644 --- a/src/Themes/Tailwind/Components/Field.php +++ b/src/Themes/Tailwind/Components/Field.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Field @@ -70,7 +70,7 @@ public function refresh(string $tag, array $alerts): void */ public function resolve(string $tag, array $alert = []): void { - $alert = !empty($alert) + $alert = ! empty($alert) ? Alert::fromArray($alert) : Alert::getField($tag, $this->name); diff --git a/src/Themes/Tailwind/Components/Message.php b/src/Themes/Tailwind/Components/Message.php index d92c6884..968bbaaa 100644 --- a/src/Themes/Tailwind/Components/Message.php +++ b/src/Themes/Tailwind/Components/Message.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Message @@ -29,7 +29,7 @@ class Message extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = !empty($alerts) + $alerts = ! empty($alerts) ? Alert::fromArrays($alerts) : Alert::getMessage($tag); @@ -40,6 +40,7 @@ public function resolve(string $tag, array $alerts = []): void ->values() ->map(function ($alert) { $alert->forget(); + return $alert->toArray(); })->toArray(); } diff --git a/src/Themes/Tailwind/Components/Modal.php b/src/Themes/Tailwind/Components/Modal.php index 03d0df98..217ad29c 100644 --- a/src/Themes/Tailwind/Components/Modal.php +++ b/src/Themes/Tailwind/Components/Modal.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Modal @@ -29,7 +29,7 @@ class Modal extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = !empty($alerts) + $alerts = ! empty($alerts) ? Alert::fromArrays($alerts) : Alert::getModal($tag); diff --git a/src/Themes/Tailwind/Components/Notify.php b/src/Themes/Tailwind/Components/Notify.php index 65beaa18..ba3da726 100644 --- a/src/Themes/Tailwind/Components/Notify.php +++ b/src/Themes/Tailwind/Components/Notify.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Notify @@ -29,7 +29,7 @@ class Notify extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = !empty($alerts) + $alerts = ! empty($alerts) ? Alert::fromArrays($alerts) : Alert::getNotify($tag); diff --git a/src/Themes/Tailwind/Components/Toastr.php b/src/Themes/Tailwind/Components/Toastr.php index dbb262c5..8c3f5e24 100644 --- a/src/Themes/Tailwind/Components/Toastr.php +++ b/src/Themes/Tailwind/Components/Toastr.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Toastr @@ -29,7 +29,7 @@ class Toastr extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = !empty($alerts) + $alerts = ! empty($alerts) ? Alert::fromArrays($alerts) : Alert::getToastr($tag); @@ -40,6 +40,7 @@ public function resolve(string $tag, array $alerts = []): void ->values() ->map(function ($alert) { $alert->forget(); + return $alert->toArray(); })->toArray(); } diff --git a/src/Themes/Tailwind/Components/ToastrClassic.php b/src/Themes/Tailwind/Components/ToastrClassic.php index ee02fa17..27a58680 100644 --- a/src/Themes/Tailwind/Components/ToastrClassic.php +++ b/src/Themes/Tailwind/Components/ToastrClassic.php @@ -4,10 +4,10 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; +use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; use Exception; use Illuminate\Contracts\View\View; use Livewire\Attributes\On; -use Digitlimit\Alert\Themes\Tailwind\AbstractComponent; /** * Class Toastr @@ -29,7 +29,7 @@ class ToastrClassic extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = !empty($alerts) + $alerts = ! empty($alerts) ? Alert::fromArrays($alerts) : Alert::getToastr($tag); @@ -40,6 +40,7 @@ public function resolve(string $tag, array $alerts = []): void ->values() ->map(function ($alert) { $alert->forget(); + return $alert->toArray(); })->toArray(); } diff --git a/src/Themes/Tailwind/Tailwind.php b/src/Themes/Tailwind/Tailwind.php index bd68953a..168603d0 100644 --- a/src/Themes/Tailwind/Tailwind.php +++ b/src/Themes/Tailwind/Tailwind.php @@ -4,12 +4,9 @@ use Digitlimit\Alert\Alert; use Digitlimit\Alert\Contracts\LivewireInterface; -use Digitlimit\Alert\Contracts\Taggable; use Digitlimit\Alert\Contracts\ThemeInterface; use Digitlimit\Alert\Foundation\AbstractTheme; -use Digitlimit\Alert\Foundation\AlertInterface; use Digitlimit\Alert\Helpers\SessionKey; -use Illuminate\Support\Collection; use Livewire\Component; use Livewire\Livewire; @@ -63,9 +60,9 @@ public static function dehydrate(): void $all = Alert::all(); foreach ($all as $type => $alerts) { - $event = 'refresh-alert-' . $type; + $event = 'refresh-alert-'.$type; - foreach($alerts as $tag => $tagAlerts) { + foreach ($alerts as $tag => $tagAlerts) { if (empty($tagAlerts)) { continue; } diff --git a/src/Themes/Tailwind/TailwindServiceProvider.php b/src/Themes/Tailwind/TailwindServiceProvider.php index 6c3bca14..a428e6d7 100644 --- a/src/Themes/Tailwind/TailwindServiceProvider.php +++ b/src/Themes/Tailwind/TailwindServiceProvider.php @@ -53,12 +53,12 @@ protected function bootForConsole(): void { // Define publishable SCSS assets $this->publishes([ - __DIR__ . '/../../../resources/scss/themes/tailwind' => resource_path('scss/alert'), + __DIR__.'/../../../resources/scss/themes/tailwind' => resource_path('scss/alert'), ], 'alert-scss'); // Define publishable compiled CSS $this->publishes([ - __DIR__ . '/../../../resources/css/themes/tailwind/alert.css' => public_path('vendor/alert/alert.css'), + __DIR__.'/../../../resources/css/themes/tailwind/alert.css' => public_path('vendor/alert/alert.css'), ], 'alert-css'); } @@ -68,7 +68,7 @@ protected function bootForConsole(): void public function registerDirectives(): void { Blade::directive('alertStyles', function () { - return ''; + return ''; }); } } diff --git a/src/Traits/WithButton.php b/src/Traits/WithButton.php index 281e2552..0ce38bdb 100644 --- a/src/Traits/WithButton.php +++ b/src/Traits/WithButton.php @@ -18,7 +18,7 @@ trait WithButton public function actionButton(): ?Button { return $this->getButtons() - ->filter(fn($button) => $button->getName() === 'action') + ->filter(fn ($button) => $button->getName() === 'action') ->first(); } @@ -28,7 +28,7 @@ public function actionButton(): ?Button public function cancelButton(): ?Button { return $this->getButtons() - ->filter(fn($button) => $button->getName() === 'cancel') + ->filter(fn ($button) => $button->getName() === 'cancel') ->first(); } @@ -38,7 +38,7 @@ public function cancelButton(): ?Button public function customButtons(): Collection { return $this->getButtons() - ->filter(fn($button) => !in_array($button->getName(), ['action', 'cancel'])); + ->filter(fn ($button) => ! in_array($button->getName(), ['action', 'cancel'])); } /** diff --git a/src/Types/Field.php b/src/Types/Field.php index eacd1935..8b949a3e 100644 --- a/src/Types/Field.php +++ b/src/Types/Field.php @@ -17,7 +17,7 @@ /** * Field alert class. */ -class Field extends AbstractAlert implements AlertInterface, HasMessage, HasName, Levelable, Taggable, HasTimeout +class Field extends AbstractAlert implements AlertInterface, HasMessage, HasName, HasTimeout, Levelable, Taggable { use Traits\Levelable; use Traits\Taggable; @@ -104,7 +104,7 @@ public static function fill(array $alert): AlertInterface */ public function getNamedTag(): string { - return $this->tag . '.' . $this->getName(); + return $this->tag.'.'.$this->getName(); } /** diff --git a/src/Types/Message.php b/src/Types/Message.php index 2f1e8647..a5855702 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -5,8 +5,8 @@ use Digitlimit\Alert\Contracts\Closable; use Digitlimit\Alert\Contracts\HasMessage; use Digitlimit\Alert\Contracts\HasSticky; -use Digitlimit\Alert\Contracts\HasTitle; use Digitlimit\Alert\Contracts\HasTimeout; +use Digitlimit\Alert\Contracts\HasTitle; use Digitlimit\Alert\Contracts\Levelable; use Digitlimit\Alert\Contracts\Taggable; use Digitlimit\Alert\Events\Message\Flashed; @@ -24,8 +24,8 @@ class Message extends AbstractAlert implements AlertInterface, Closable, HasMess use Traits\Taggable; use Traits\WithMessage; use Traits\WithSticky; - use Traits\WithTitle; use Traits\WithTimeout; + use Traits\WithTitle; /** * The default level of the alert. diff --git a/src/Types/Modal.php b/src/Types/Modal.php index 5368b6a7..f35cf608 100644 --- a/src/Types/Modal.php +++ b/src/Types/Modal.php @@ -33,8 +33,8 @@ class Modal extends AbstractAlert implements AlertInterface, Closable, HasButton use Traits\WithButton; use Traits\WithCancelButton; use Traits\WithMessage; - use Traits\WithTitle; use Traits\WithTimeout; + use Traits\WithTitle; use Traits\WithView; /** @@ -92,7 +92,7 @@ public static function fill(array $alert): AlertInterface $modal->buttons($alert['buttons'] ?? []); foreach (['tag', 'size', 'level', 'title', 'view'] as $property) { - if (!empty($alert[$property])) { + if (! empty($alert[$property])) { $method = $property === 'view' ? 'setView' : $property; $modal->$method($alert[$property]); } diff --git a/src/Types/Notify.php b/src/Types/Notify.php index 079e5725..776e3c1e 100644 --- a/src/Types/Notify.php +++ b/src/Types/Notify.php @@ -27,12 +27,12 @@ class Notify extends AbstractAlert implements AlertInterface, Closable, HasButto use Traits\Levelable; use Traits\Positionable; use Traits\Taggable; - use Traits\WithMessage; - use Traits\WithTimeout; - use Traits\WithTitle; use Traits\WithActionButton; use Traits\WithButton; use Traits\WithCancelButton; + use Traits\WithMessage; + use Traits\WithTimeout; + use Traits\WithTitle; protected string $defaultLevel = 'info'; @@ -116,8 +116,8 @@ public static function fill(array $alert): AlertInterface public function getIdTag(): string { return $this->tag - . '.' - . $this->getId(); + .'.' + .$this->getId(); } /** diff --git a/tests/TestCase.php b/tests/TestCase.php index 4fb91501..6ce73b92 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,8 +6,8 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Testing\Concerns\InteractsWithViews; use Illuminate\Support\Facades\Facade; -use Orchestra\Testbench\TestCase as BaseTestCase; use Livewire; +use Orchestra\Testbench\TestCase as BaseTestCase; class TestCase extends BaseTestCase { diff --git a/tests/Unit/Factory/AlertFactoryTest.php b/tests/Unit/Factory/AlertFactoryTest.php index 76e31e5f..9d598a09 100644 --- a/tests/Unit/Factory/AlertFactoryTest.php +++ b/tests/Unit/Factory/AlertFactoryTest.php @@ -11,7 +11,6 @@ ->toBe('Hello World'); })->group('unit', 'factory', 'alert-factory'); - it('creates an alert using makeFromArray()', function () { $alert = AlertFactory::makeFromArray([ 'id' => 1, @@ -25,4 +24,4 @@ expect($alert)->toBeInstanceOf(AlertInterface::class) ->and($alert->getMessage()) ->toBe('Hello World'); -})->group('unit', 'factory', 'alert-factory'); \ No newline at end of file +})->group('unit', 'factory', 'alert-factory'); diff --git a/tests/Unit/Foundation/AbstractAlertTest.php b/tests/Unit/Foundation/AbstractAlertTest.php index 16a22e7b..5a09d2c3 100644 --- a/tests/Unit/Foundation/AbstractAlertTest.php +++ b/tests/Unit/Foundation/AbstractAlertTest.php @@ -1,16 +1,17 @@ id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; + return $instance; } }; @@ -37,7 +39,8 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'auto-set-id'); it('can manually set ID', function () { - $alert = new class extends AbstractAlert { + $alert = new class extends AbstractAlert + { public string $message = 'Test Alert'; public function key(): string @@ -52,9 +55,10 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self(); + $instance = new self; $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; + return $instance; } }; @@ -66,7 +70,8 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'manual-set-id'); it('flashes alert to session if id and message are set', function () { - $alert = new class extends AbstractAlert { + $alert = new class extends AbstractAlert + { public string $message = 'Hello session'; public function key(): string @@ -81,9 +86,10 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self(); + $instance = new self; $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; + return $instance; } }; @@ -95,7 +101,8 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'flash-session'); it('does not flash if message is empty', function () { - $alert = new class extends AbstractAlert { + $alert = new class extends AbstractAlert + { public function key(): string { return 'session_alert'; @@ -108,9 +115,10 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self(); + $instance = new self; $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? ''; + return $instance; } }; @@ -122,7 +130,8 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'no-flash-empty-message'); it('can forget session key', function () { - $alert = new class extends AbstractAlert { + $alert = new class extends AbstractAlert + { public string $message = 'Forget me'; public function key(): string @@ -137,9 +146,10 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self(); + $instance = new self; $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; + return $instance; } }; @@ -155,7 +165,8 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'forget-session'); it('can convert to array and json', function () { - $alert = new class extends AbstractAlert { + $alert = new class extends AbstractAlert + { public string $message = 'Format test'; public function key(): string @@ -170,9 +181,10 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self(); + $instance = new self; $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; + return $instance; } }; diff --git a/tests/Unit/Icons/ErrorTest.php b/tests/Unit/Icons/ErrorTest.php index 6a3d2877..c8650281 100644 --- a/tests/Unit/Icons/ErrorTest.php +++ b/tests/Unit/Icons/ErrorTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Error(); + $component = new Error; expect($component->isCircled())->toBeTrue(); })->group('icons', 'error-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.error', [], []) ->andReturn('rendered-view'); - $component = new Error(); + $component = new Error; expect($component->render())->toBe('rendered-view'); })->group('icons', 'error-icon', 'view'); diff --git a/tests/Unit/Icons/InfoTest.php b/tests/Unit/Icons/InfoTest.php index 8af1f11e..4dc97db2 100644 --- a/tests/Unit/Icons/InfoTest.php +++ b/tests/Unit/Icons/InfoTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Info(); + $component = new Info; expect($component->isCircled())->toBeTrue(); })->group('icons', 'info-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.info', [], []) ->andReturn('rendered-view'); - $component = new Info(); + $component = new Info; expect($component->render())->toBe('rendered-view'); })->group('icons', 'info-icon', 'view'); diff --git a/tests/Unit/Icons/SuccessTest.php b/tests/Unit/Icons/SuccessTest.php index 1f894c5e..bd623363 100644 --- a/tests/Unit/Icons/SuccessTest.php +++ b/tests/Unit/Icons/SuccessTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Success(); + $component = new Success; expect($component->isCircled())->toBeTrue(); })->group('icons', 'success-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.success', [], []) ->andReturn('rendered-view'); - $component = new Success(); + $component = new Success; expect($component->render())->toBe('rendered-view'); })->group('icons', 'success-icon', 'view'); diff --git a/tests/Unit/Icons/WarningTest.php b/tests/Unit/Icons/WarningTest.php index 396b88c3..a3c5dfcc 100644 --- a/tests/Unit/Icons/WarningTest.php +++ b/tests/Unit/Icons/WarningTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Warning(); + $component = new Warning; expect($component->isCircled())->toBeTrue(); })->group('icons', 'warning-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.warning', [], []) ->andReturn('rendered-view'); - $component = new Warning(); + $component = new Warning; expect($component->render())->toBe('rendered-view'); })->group('icons', 'warning-icon', 'view'); diff --git a/tests/Unit/Themes/Tailwind/Components/FieldTest.php b/tests/Unit/Themes/Tailwind/Components/FieldTest.php index 49ecce07..7651b63d 100644 --- a/tests/Unit/Themes/Tailwind/Components/FieldTest.php +++ b/tests/Unit/Themes/Tailwind/Components/FieldTest.php @@ -7,4 +7,4 @@ Livewire::test(Field::class, ['for' => 'test-field']) ->assertSet('name', 'test-field') ->assertSet('alert', []); -})->group('tailwind', 'components', 'field'); \ No newline at end of file +})->group('tailwind', 'components', 'field'); diff --git a/tests/Unit/Types/FieldTest.php b/tests/Unit/Types/FieldTest.php index c012544a..a13f8e8e 100644 --- a/tests/Unit/Types/FieldTest.php +++ b/tests/Unit/Types/FieldTest.php @@ -1,10 +1,10 @@ tag('register'); - $sessionKey = Alert::MAIN_KEY . '.field.register.username'; + $sessionKey = Alert::MAIN_KEY.'.field.register.username'; $alert->flash(); diff --git a/tests/Unit/Types/MessageTest.php b/tests/Unit/Types/MessageTest.php index c3ef2059..4d1f4e89 100644 --- a/tests/Unit/Types/MessageTest.php +++ b/tests/Unit/Types/MessageTest.php @@ -1,10 +1,10 @@ tag('intro'); $alert->flash(); - $sessionKey = Alert::MAIN_KEY . '.message.default.' . $alert->getId(); + $sessionKey = Alert::MAIN_KEY.'.message.default.'.$alert->getId(); expect(Session::get($sessionKey))->toBeInstanceOf(Message::class) ->and(Session::get($sessionKey)->getMessage())->toBe('Welcome to the app'); diff --git a/tests/Unit/Types/ModalTest.php b/tests/Unit/Types/ModalTest.php index 110c589b..564c612e 100644 --- a/tests/Unit/Types/ModalTest.php +++ b/tests/Unit/Types/ModalTest.php @@ -1,10 +1,10 @@ setView('modals.confirm') ->buttons([ ['name' => 'cancel', 'label' => 'Cancel'], - ['name' => 'confirm', 'label' => 'Yes, Confirm'] + ['name' => 'confirm', 'label' => 'Yes, Confirm'], ]); $array = $alert->toArray(); expect($array)->toMatchArray([ - "id" => $alert->getId(), - "type" => "modal", - "level" => "info", - "title" => "Confirm Action", - "message" => "Modal Message", - "tag" => "confirm", - "size" => "medium", - "timeout" => 30, - "scrollable" => true, - "closable" => true, - "view" => "modals.confirm", - "buttons" => [ + 'id' => $alert->getId(), + 'type' => 'modal', + 'level' => 'info', + 'title' => 'Confirm Action', + 'message' => 'Modal Message', + 'tag' => 'confirm', + 'size' => 'medium', + 'timeout' => 30, + 'scrollable' => true, + 'closable' => true, + 'view' => 'modals.confirm', + 'buttons' => [ [ - "id" => $alert->cancelButton()->getId(), - "name" => "cancel", - "label" => "Cancel", - "link" => null, - "attributes" => [], + 'id' => $alert->cancelButton()->getId(), + 'name' => 'cancel', + 'label' => 'Cancel', + 'link' => null, + 'attributes' => [], ], [ - "id" => $alert->customButtons()->first()->getId(), - "name" => "confirm", - "label" => "Yes, Confirm", - "link" => null, - "attributes" => [] - ] - ] + 'id' => $alert->customButtons()->first()->getId(), + 'name' => 'confirm', + 'label' => 'Yes, Confirm', + 'link' => null, + 'attributes' => [], + ], + ], ]); })->group('modal', 'toArray'); @@ -87,7 +87,7 @@ 'view' => 'modals.continue', 'buttons' => [ ['name' => 'no', 'label' => 'No'], - ['name' => 'yes', 'label' => 'Yes'] + ['name' => 'yes', 'label' => 'Yes'], ], ]; @@ -112,7 +112,7 @@ $alert->flash(); - $sessionKey = SessionKey::key('modal', 'example.' . $alert->getId()); + $sessionKey = SessionKey::key('modal', 'example.'.$alert->getId()); expect(Session::get($sessionKey))->toBeInstanceOf(Modal::class) ->and(Session::get($sessionKey)->getMessage())->toBe('Flashing modal'); diff --git a/tests/Unit/Types/NotifyTest.php b/tests/Unit/Types/NotifyTest.php index c35f724f..08589a35 100644 --- a/tests/Unit/Types/NotifyTest.php +++ b/tests/Unit/Types/NotifyTest.php @@ -1,8 +1,6 @@ toArray(); expect($array)->toHaveKeys([ - 'type', 'title', 'timeout', 'message', 'tag', 'id_tag', 'level', 'position', 'closable', 'buttons' + 'type', 'title', 'timeout', 'message', 'tag', 'id_tag', 'level', 'position', 'closable', 'buttons', ])->and($array['message'])->toBe('Test message') ->and($array['title'])->toBe('Test Title') ->and($array['tag'])->toBe('test-tag'); @@ -52,4 +50,3 @@ ->and($notify->getPosition())->toBe('top-right') ->and($notify->isClosable())->toBeTrue(); })->group('notify', 'fill'); - diff --git a/tests/Unit/Types/ToastrTest.php b/tests/Unit/Types/ToastrTest.php index f8e46469..5476338b 100644 --- a/tests/Unit/Types/ToastrTest.php +++ b/tests/Unit/Types/ToastrTest.php @@ -1,7 +1,7 @@ Date: Sun, 20 Apr 2025 15:39:17 +0000 Subject: [PATCH 7/8] Apply fixes from StyleCI [ci skip] [skip ci] --- config/alert.php | 32 +++++------ src/Alert.php | 10 ++-- src/Component/Button.php | 10 ++-- src/Contracts/Closable.php | 8 +-- src/Contracts/HasButton.php | 2 +- src/Contracts/HasMessage.php | 2 +- src/Contracts/HasName.php | 2 +- src/Contracts/Sizable.php | 4 +- src/Events/Field/Flashed.php | 7 ++- src/Events/Message/Flashed.php | 7 ++- src/Events/Modal/Flashed.php | 7 ++- src/Events/Notify/Flashed.php | 7 ++- src/Events/Toastr/Flashed.php | 7 ++- src/Factory/AlertFactory.php | 4 +- src/Foundation/AbstractAlert.php | 4 +- src/Foundation/AbstractTheme.php | 4 +- src/Helpers.php | 12 ++-- src/Helpers/Theme.php | 2 +- src/Helpers/Type.php | 2 +- src/Helpers/ValidationError.php | 4 +- src/Themes/Tailwind/AbstractComponent.php | 4 +- src/Themes/Tailwind/Components/Field.php | 10 ++-- src/Themes/Tailwind/Components/Message.php | 6 +- src/Themes/Tailwind/Components/Modal.php | 6 +- src/Themes/Tailwind/Components/Notify.php | 6 +- src/Themes/Tailwind/Components/Toastr.php | 6 +- .../Tailwind/Components/ToastrClassic.php | 6 +- src/Themes/Tailwind/Tailwind.php | 8 +-- .../Tailwind/TailwindServiceProvider.php | 2 +- src/Themes/Tailwind/Utils/Css.php | 18 +++--- src/Traits/Positionable.php | 2 +- src/Traits/Sizable.php | 8 +-- src/Traits/WithButton.php | 6 +- src/Traits/WithTitle.php | 2 +- src/Traits/WithView.php | 2 +- src/Types/Field.php | 12 ++-- src/Types/Message.php | 14 ++--- src/Types/Modal.php | 22 ++++---- src/Types/Notify.php | 16 +++--- src/Types/Toastr.php | 12 ++-- src/Types/ToastrClassic.php | 12 ++-- tests/TestCase.php | 3 +- tests/Unit/Component/ButtonTest.php | 14 ++--- tests/Unit/Factory/AlertFactoryTest.php | 10 ++-- tests/Unit/Foundation/AbstractAlertTest.php | 30 ++++------ tests/Unit/Helpers/AttributeTest.php | 3 +- tests/Unit/Helpers/ThemeTest.php | 3 - tests/Unit/Icons/ErrorTest.php | 4 +- tests/Unit/Icons/InfoTest.php | 4 +- tests/Unit/Icons/SuccessTest.php | 4 +- tests/Unit/Icons/WarningTest.php | 4 +- tests/Unit/Types/FieldTest.php | 22 ++++---- tests/Unit/Types/MessageTest.php | 25 ++++----- tests/Unit/Types/ModalTest.php | 56 +++++++++---------- tests/Unit/Types/NotifyTest.php | 14 ++--- tests/Unit/Types/ToastrTest.php | 24 ++++---- workbench/app/Models/User.php | 5 +- workbench/database/factories/UserFactory.php | 8 +-- workbench/database/seeders/DatabaseSeeder.php | 2 +- 59 files changed, 281 insertions(+), 271 deletions(-) diff --git a/config/alert.php b/config/alert.php index 6e495f8d..5da7adb5 100644 --- a/config/alert.php +++ b/config/alert.php @@ -30,9 +30,9 @@ 'icons' => [ 'success' => \Digitlimit\Alert\Icons\Success::class, - 'error' => \Digitlimit\Alert\Icons\Error::class, + 'error' => \Digitlimit\Alert\Icons\Error::class, 'warning' => \Digitlimit\Alert\Icons\Warning::class, - 'info' => \Digitlimit\Alert\Icons\Info::class, + 'info' => \Digitlimit\Alert\Icons\Info::class, ], /* @@ -46,32 +46,32 @@ 'tailwind' => [ 'types' => [ 'message' => [ - 'view' => 'alert-message', - 'alert' => Types\Message::class, + 'view' => 'alert-message', + 'alert' => Types\Message::class, 'component' => Themes\Tailwind\Components\Message::class, ], 'field' => [ - 'view' => 'alert-field', - 'alert' => Types\Field::class, + 'view' => 'alert-field', + 'alert' => Types\Field::class, 'component' => Themes\Tailwind\Components\Field::class, ], 'modal' => [ - 'view' => 'alert-modal', - 'alert' => Types\Modal::class, + 'view' => 'alert-modal', + 'alert' => Types\Modal::class, 'component' => Themes\Tailwind\Components\Modal::class, ], 'toastr' => [ - 'view' => 'alert-toastr', - 'alert' => Types\Toastr::class, + 'view' => 'alert-toastr', + 'alert' => Types\Toastr::class, 'component' => Themes\Tailwind\Components\Toastr::class, ], 'notify' => [ - 'view' => 'alert-notify', - 'alert' => Types\Notify::class, + 'view' => 'alert-notify', + 'alert' => Types\Notify::class, 'component' => Themes\Tailwind\Components\Notify::class, ], ], @@ -79,21 +79,21 @@ 'attributes' => [ 'buttons' => [ 'action' => [ - 'type' => 'button', + 'type' => 'button', '@click' => 'show = false;', ], 'cancel' => [ - 'type' => 'button', + 'type' => 'button', '@click' => 'show = false;', ], ], 'links' => [ 'action' => [ - 'type' => 'button', + 'type' => 'button', '@click' => 'show = false;', ], 'cancel' => [ - 'type' => 'button', + 'type' => 'button', '@click' => 'show = false;', ], ], diff --git a/src/Alert.php b/src/Alert.php index 50b858f5..143b62ec 100644 --- a/src/Alert.php +++ b/src/Alert.php @@ -43,7 +43,7 @@ public static function typeKey(string $type): string */ public static function named(string $type, string $name, string $tag): ?HasName { - if (! Type::exists($type)) { + if (!Type::exists($type)) { throw new Exception("Invalid alert type '$type'. Check the alert config"); } @@ -61,7 +61,7 @@ public static function named(string $type, string $name, string $tag): ?HasName */ public static function tagged(string $type, string $tag): Collection { - if (! Type::exists($type)) { + if (!Type::exists($type)) { throw new Exception("Invalid alert type '$type'. Check the alert config"); } @@ -79,7 +79,7 @@ public static function tagged(string $type, string $tag): Collection */ public static function from(string $type, ...$args): AlertInterface { - if (! Type::exists($type)) { + if (!Type::exists($type)) { throw new Exception("Invalid alert type '$type'. Check the alert config"); } @@ -152,7 +152,7 @@ public static function fromArray(array $alert): ?AlertInterface $type = $alert['type'] ?? null; - if (! $type || ! Type::exists($type)) { + if (!$type || !Type::exists($type)) { throw new Exception("Invalid alert type '$type'. Check the alert config"); } @@ -176,7 +176,7 @@ public static function has(string $type): bool { $types = Session::get(SessionKey::typeKey($type)) ?? []; - return ! empty($types); + return !empty($types); } /** diff --git a/src/Component/Button.php b/src/Component/Button.php index e09e8e16..b37f303c 100644 --- a/src/Component/Button.php +++ b/src/Component/Button.php @@ -116,7 +116,7 @@ public function getLabel(): ?string */ public function isLink(): bool { - return ! empty($this->link); + return !empty($this->link); } /** @@ -141,10 +141,10 @@ public function isCancel(): bool public function toArray(): array { return [ - 'id' => $this->getId(), - 'name' => $this->getName(), - 'label' => $this->getLabel(), - 'link' => $this->getLink(), + 'id' => $this->getId(), + 'name' => $this->getName(), + 'label' => $this->getLabel(), + 'link' => $this->getLink(), 'attributes' => $this->getAttributes(), ]; } diff --git a/src/Contracts/Closable.php b/src/Contracts/Closable.php index b854c06c..8af759f1 100644 --- a/src/Contracts/Closable.php +++ b/src/Contracts/Closable.php @@ -3,26 +3,26 @@ namespace Digitlimit\Alert\Contracts; /** - * Alert closable contract + * Alert closable contract. */ interface Closable { /** - * Set the alert to be closable + * Set the alert to be closable. * * @return $this */ public function closable(bool $closable): self; /** - * Set the alert to be not closable + * Set the alert to be not closable. * * @return $this */ public function notClosable(): self; /** - * Check if the alert is closable + * Check if the alert is closable. */ public function isClosable(): bool; } diff --git a/src/Contracts/HasButton.php b/src/Contracts/HasButton.php index 7a61132b..dbd0bc79 100644 --- a/src/Contracts/HasButton.php +++ b/src/Contracts/HasButton.php @@ -5,7 +5,7 @@ use Illuminate\Support\Collection; /** - * Alert button contract + * Alert button contract. */ interface HasButton { diff --git a/src/Contracts/HasMessage.php b/src/Contracts/HasMessage.php index 15f71e4e..363ad5e4 100644 --- a/src/Contracts/HasMessage.php +++ b/src/Contracts/HasMessage.php @@ -3,7 +3,7 @@ namespace Digitlimit\Alert\Contracts; /** - * Alert message contract + * Alert message contract. */ interface HasMessage { diff --git a/src/Contracts/HasName.php b/src/Contracts/HasName.php index f5daf94d..438320ba 100644 --- a/src/Contracts/HasName.php +++ b/src/Contracts/HasName.php @@ -3,7 +3,7 @@ namespace Digitlimit\Alert\Contracts; /** - * Has name contract + * Has name contract. */ interface HasName { diff --git a/src/Contracts/Sizable.php b/src/Contracts/Sizable.php index 484b6bc0..23b37549 100644 --- a/src/Contracts/Sizable.php +++ b/src/Contracts/Sizable.php @@ -35,14 +35,14 @@ public function extraLarge(): self; public function fullscreen(): self; /** - * Set modal size + * Set modal size. * * @throws Exception */ public function size(string $size): self; /** - * Get the size of the alert + * Get the size of the alert. */ public function getSize(): string; } diff --git a/src/Events/Field/Flashed.php b/src/Events/Field/Flashed.php index 8f6bb08c..89a9b9b7 100644 --- a/src/Events/Field/Flashed.php +++ b/src/Events/Field/Flashed.php @@ -11,14 +11,17 @@ class Flashed { - use Dispatchable, InteractsWithSockets, SerializesModels; + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. */ public function __construct( public Field $alert - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/src/Events/Message/Flashed.php b/src/Events/Message/Flashed.php index 57c53064..82a0270c 100644 --- a/src/Events/Message/Flashed.php +++ b/src/Events/Message/Flashed.php @@ -11,14 +11,17 @@ class Flashed { - use Dispatchable, InteractsWithSockets, SerializesModels; + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. */ public function __construct( public Message $alert - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/src/Events/Modal/Flashed.php b/src/Events/Modal/Flashed.php index 5fc7fa87..2329ec7d 100644 --- a/src/Events/Modal/Flashed.php +++ b/src/Events/Modal/Flashed.php @@ -11,14 +11,17 @@ class Flashed { - use Dispatchable, InteractsWithSockets, SerializesModels; + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. */ public function __construct( public Modal $alert - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/src/Events/Notify/Flashed.php b/src/Events/Notify/Flashed.php index f934e2c1..8f66c94a 100644 --- a/src/Events/Notify/Flashed.php +++ b/src/Events/Notify/Flashed.php @@ -11,14 +11,17 @@ class Flashed { - use Dispatchable, InteractsWithSockets, SerializesModels; + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. */ public function __construct( public Notify $alert - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/src/Events/Toastr/Flashed.php b/src/Events/Toastr/Flashed.php index faa3f782..0b3c5ab4 100644 --- a/src/Events/Toastr/Flashed.php +++ b/src/Events/Toastr/Flashed.php @@ -11,14 +11,17 @@ class Flashed { - use Dispatchable, InteractsWithSockets, SerializesModels; + use Dispatchable; + use InteractsWithSockets; + use SerializesModels; /** * Create a new event instance. */ public function __construct( public Toastr $alert - ) {} + ) { + } /** * Get the channels the event should broadcast on. diff --git a/src/Factory/AlertFactory.php b/src/Factory/AlertFactory.php index d546fd8f..46b5d2da 100644 --- a/src/Factory/AlertFactory.php +++ b/src/Factory/AlertFactory.php @@ -20,7 +20,7 @@ public static function make(string $type, ...$args): AlertInterface { $class = Type::classname($type); - if (! class_exists($class)) { + if (!class_exists($class)) { throw new Exception("Alert type '$class' class not found "); } @@ -37,7 +37,7 @@ public static function makeFromArray(array $alert): AlertInterface $type = $alert['type']; $class = Type::classname($type); - if (! class_exists($class)) { + if (!class_exists($class)) { throw new Exception("Alert type '$class' class not found "); } diff --git a/src/Foundation/AbstractAlert.php b/src/Foundation/AbstractAlert.php index 7f76ccc8..df2bd5a4 100644 --- a/src/Foundation/AbstractAlert.php +++ b/src/Foundation/AbstractAlert.php @@ -35,7 +35,7 @@ public function __construct() */ public function id(string|int $id): self { - if (! empty($this->id) && $this->id !== $id) { + if (!empty($this->id) && $this->id !== $id) { $this->forget(); } @@ -50,7 +50,7 @@ public function id(string|int $id): self */ public function autoSetId(): self { - if (! empty($this->id)) { + if (!empty($this->id)) { return $this; } diff --git a/src/Foundation/AbstractTheme.php b/src/Foundation/AbstractTheme.php index 846931eb..2a17e449 100644 --- a/src/Foundation/AbstractTheme.php +++ b/src/Foundation/AbstractTheme.php @@ -4,4 +4,6 @@ use Digitlimit\Alert\Contracts\ThemeInterface; -abstract class AbstractTheme implements ThemeInterface {} +abstract class AbstractTheme implements ThemeInterface +{ +} diff --git a/src/Helpers.php b/src/Helpers.php index 9bae65ff..4c2ca604 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -7,7 +7,7 @@ use Digitlimit\Alert\Types\Notify; use Digitlimit\Alert\Types\Toastr; -if (! function_exists('alert')) { +if (!function_exists('alert')) { function alert(string $message, ?string $title = null): Message { $alert = app('alert') @@ -21,14 +21,14 @@ function alert(string $message, ?string $title = null): Message } } -if (! function_exists('field')) { +if (!function_exists('field')) { function field(string $name, string $message): Field { return app('alert')->field($name, $message); } } -if (! function_exists('modal')) { +if (!function_exists('modal')) { function modal(string $message, ?string $title = null): Modal { $alert = app('alert')->modal($message); @@ -41,7 +41,7 @@ function modal(string $message, ?string $title = null): Modal } } -if (! function_exists('toastr')) { +if (!function_exists('toastr')) { function toastr(string $message, ?string $title = null): Toastr { $alert = app('alert')->toastr($message); @@ -54,7 +54,7 @@ function toastr(string $message, ?string $title = null): Toastr } } -if (! function_exists('notify')) { +if (!function_exists('notify')) { function notify(string $message, ?string $title = null): Notify { $alert = app('alert')->notify($message); @@ -67,7 +67,7 @@ function notify(string $message, ?string $title = null): Notify } } -if (! function_exists('forgetAlert')) { +if (!function_exists('forgetAlert')) { function forgetAlert(string $type, string $tag = Alert::DEFAULT_TAG): void { app('alert')->forget($type, $tag); diff --git a/src/Helpers/Theme.php b/src/Helpers/Theme.php index 872d63a4..30971ca6 100644 --- a/src/Helpers/Theme.php +++ b/src/Helpers/Theme.php @@ -31,7 +31,7 @@ public static function theme(): ThemeInterface $theme = $themes[$name] ?? null; - if (! $theme) { + if (!$theme) { throw new Exception("Theme {$name} not found"); } diff --git a/src/Helpers/Type.php b/src/Helpers/Type.php index f4dd74fc..3e94ebe4 100644 --- a/src/Helpers/Type.php +++ b/src/Helpers/Type.php @@ -57,7 +57,7 @@ public static function type(string $type): array */ public static function classname(string $type): string { - if (! self::exists($type)) { + if (!self::exists($type)) { throw new Exception("The alert type '$type' does not exist in config"); } diff --git a/src/Helpers/ValidationError.php b/src/Helpers/ValidationError.php index ed3dc040..04e06c32 100644 --- a/src/Helpers/ValidationError.php +++ b/src/Helpers/ValidationError.php @@ -15,7 +15,7 @@ public function errors(): MessageBag return $errors instanceof MessageBag ? $errors - : new MessageBag; + : new MessageBag(); } /** @@ -23,7 +23,7 @@ public function errors(): MessageBag */ public function taggedErrors(string $tag): MessageBag { - return $this->errors()->{$tag} ?? new MessageBag; + return $this->errors()->{$tag} ?? new MessageBag(); } /** diff --git a/src/Themes/Tailwind/AbstractComponent.php b/src/Themes/Tailwind/AbstractComponent.php index 01ea93f2..4a3dc9c4 100644 --- a/src/Themes/Tailwind/AbstractComponent.php +++ b/src/Themes/Tailwind/AbstractComponent.php @@ -4,4 +4,6 @@ use Livewire\Component; -abstract class AbstractComponent extends Component {} +abstract class AbstractComponent extends Component +{ +} diff --git a/src/Themes/Tailwind/Components/Field.php b/src/Themes/Tailwind/Components/Field.php index 84495a71..a3b1e496 100644 --- a/src/Themes/Tailwind/Components/Field.php +++ b/src/Themes/Tailwind/Components/Field.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Field + * Class Field. */ class Field extends AbstractComponent implements LivewireInterface { @@ -20,12 +20,12 @@ class Field extends AbstractComponent implements LivewireInterface public ?string $for = null; /** - * The alert name + * The alert name. */ public ?string $name = null; /** - * The alerts + * The alerts. */ public array $alert = []; @@ -41,7 +41,7 @@ class Field extends AbstractComponent implements LivewireInterface */ public function mount(): void { - if (! empty($this->for)) { + if (!empty($this->for)) { $this->name = $this->for; } @@ -70,7 +70,7 @@ public function refresh(string $tag, array $alerts): void */ public function resolve(string $tag, array $alert = []): void { - $alert = ! empty($alert) + $alert = !empty($alert) ? Alert::fromArray($alert) : Alert::getField($tag, $this->name); diff --git a/src/Themes/Tailwind/Components/Message.php b/src/Themes/Tailwind/Components/Message.php index 968bbaaa..c923c1bd 100644 --- a/src/Themes/Tailwind/Components/Message.php +++ b/src/Themes/Tailwind/Components/Message.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Message + * Class Message. */ class Message extends AbstractComponent implements LivewireInterface { @@ -20,7 +20,7 @@ class Message extends AbstractComponent implements LivewireInterface public string $tag = Alert::DEFAULT_TAG; /** - * The alerts + * The alerts. */ public array $alerts = []; @@ -29,7 +29,7 @@ class Message extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = ! empty($alerts) + $alerts = !empty($alerts) ? Alert::fromArrays($alerts) : Alert::getMessage($tag); diff --git a/src/Themes/Tailwind/Components/Modal.php b/src/Themes/Tailwind/Components/Modal.php index 217ad29c..477eeb45 100644 --- a/src/Themes/Tailwind/Components/Modal.php +++ b/src/Themes/Tailwind/Components/Modal.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Modal + * Class Modal. */ class Modal extends AbstractComponent implements LivewireInterface { @@ -20,7 +20,7 @@ class Modal extends AbstractComponent implements LivewireInterface public string $tag = Alert::DEFAULT_TAG; /** - * The alerts + * The alerts. */ public array $alerts = []; @@ -29,7 +29,7 @@ class Modal extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = ! empty($alerts) + $alerts = !empty($alerts) ? Alert::fromArrays($alerts) : Alert::getModal($tag); diff --git a/src/Themes/Tailwind/Components/Notify.php b/src/Themes/Tailwind/Components/Notify.php index ba3da726..6ba0b7d8 100644 --- a/src/Themes/Tailwind/Components/Notify.php +++ b/src/Themes/Tailwind/Components/Notify.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Notify + * Class Notify. */ class Notify extends AbstractComponent implements LivewireInterface { @@ -20,7 +20,7 @@ class Notify extends AbstractComponent implements LivewireInterface public string $tag = Alert::DEFAULT_TAG; /** - * The alerts + * The alerts. */ public array $alerts = []; @@ -29,7 +29,7 @@ class Notify extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = ! empty($alerts) + $alerts = !empty($alerts) ? Alert::fromArrays($alerts) : Alert::getNotify($tag); diff --git a/src/Themes/Tailwind/Components/Toastr.php b/src/Themes/Tailwind/Components/Toastr.php index 8c3f5e24..960e1973 100644 --- a/src/Themes/Tailwind/Components/Toastr.php +++ b/src/Themes/Tailwind/Components/Toastr.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Toastr + * Class Toastr. */ class Toastr extends AbstractComponent implements LivewireInterface { @@ -20,7 +20,7 @@ class Toastr extends AbstractComponent implements LivewireInterface public string $tag = Alert::DEFAULT_TAG; /** - * The alerts + * The alerts. */ public array $alerts = []; @@ -29,7 +29,7 @@ class Toastr extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = ! empty($alerts) + $alerts = !empty($alerts) ? Alert::fromArrays($alerts) : Alert::getToastr($tag); diff --git a/src/Themes/Tailwind/Components/ToastrClassic.php b/src/Themes/Tailwind/Components/ToastrClassic.php index 27a58680..7546f714 100644 --- a/src/Themes/Tailwind/Components/ToastrClassic.php +++ b/src/Themes/Tailwind/Components/ToastrClassic.php @@ -10,7 +10,7 @@ use Livewire\Attributes\On; /** - * Class Toastr + * Class Toastr. */ class ToastrClassic extends AbstractComponent implements LivewireInterface { @@ -20,7 +20,7 @@ class ToastrClassic extends AbstractComponent implements LivewireInterface public string $tag = Alert::DEFAULT_TAG; /** - * The alerts + * The alerts. */ public array $alerts = []; @@ -29,7 +29,7 @@ class ToastrClassic extends AbstractComponent implements LivewireInterface */ public function resolve(string $tag, array $alerts = []): void { - $alerts = ! empty($alerts) + $alerts = !empty($alerts) ? Alert::fromArrays($alerts) : Alert::getToastr($tag); diff --git a/src/Themes/Tailwind/Tailwind.php b/src/Themes/Tailwind/Tailwind.php index 168603d0..390e517b 100644 --- a/src/Themes/Tailwind/Tailwind.php +++ b/src/Themes/Tailwind/Tailwind.php @@ -16,7 +16,7 @@ class Tailwind extends AbstractTheme implements ThemeInterface { /** - * Register the alert types + * Register the alert types. */ public static function types(): array { @@ -24,7 +24,7 @@ public static function types(): array } /** - * Register the alert components + * Register the alert components. */ public static function registerComponents(): void { @@ -36,12 +36,12 @@ public static function registerComponents(): void } /** - * Dehydrate the alert to the component + * Dehydrate the alert to the component. */ public static function dehydrate(): void { on('dehydrate', function (Component $component) { - if (! Livewire::isLivewireRequest()) { + if (!Livewire::isLivewireRequest()) { return false; } diff --git a/src/Themes/Tailwind/TailwindServiceProvider.php b/src/Themes/Tailwind/TailwindServiceProvider.php index a428e6d7..53d8bfc3 100644 --- a/src/Themes/Tailwind/TailwindServiceProvider.php +++ b/src/Themes/Tailwind/TailwindServiceProvider.php @@ -63,7 +63,7 @@ protected function bootForConsole(): void } /** - * Register directives + * Register directives. */ public function registerDirectives(): void { diff --git a/src/Themes/Tailwind/Utils/Css.php b/src/Themes/Tailwind/Utils/Css.php index fef9efb6..f278240b 100644 --- a/src/Themes/Tailwind/Utils/Css.php +++ b/src/Themes/Tailwind/Utils/Css.php @@ -5,17 +5,17 @@ use Illuminate\Support\Facades\Session; /** - * Class Css + * Class Css. */ class Css { /** - * The classes + * The classes. */ protected array $classes; /** - * The cache key + * The cache key. */ protected string $cacheKey = 'digitlimit_alert_unique_tailwind_classes'; @@ -25,7 +25,7 @@ public function __construct(array $classes = []) } /** - * Set the classes + * Set the classes. */ public function setClasses(array $classes): self { @@ -35,7 +35,7 @@ public function setClasses(array $classes): self } /** - * Flush the cache + * Flush the cache. */ public function forgetCache(): void { @@ -43,7 +43,7 @@ public function forgetCache(): void } /** - * Retrieve unique Tailwind classes with caching + * Retrieve unique Tailwind classes with caching. */ public function uniqueClasses(): array { @@ -58,7 +58,7 @@ public function uniqueClasses(): array } /** - * Recursively extract unique Tailwind classes from the provided array + * Recursively extract unique Tailwind classes from the provided array. */ protected function extractUniqueClasses(array $array): array { @@ -74,7 +74,7 @@ protected function extractUniqueClasses(array $array): array } /** - * Convert the classes to a string + * Convert the classes to a string. */ public function toString(): string { @@ -82,7 +82,7 @@ public function toString(): string } /** - * Convert the classes to a string + * Convert the classes to a string. */ public function __toString(): string { diff --git a/src/Traits/Positionable.php b/src/Traits/Positionable.php index 4870df04..fec9eb9d 100644 --- a/src/Traits/Positionable.php +++ b/src/Traits/Positionable.php @@ -95,7 +95,7 @@ public function position(string $position): self $method = Str::camel($position); // check if function exists - if (! method_exists($this, $method)) { + if (!method_exists($this, $method)) { throw new Exception("Position method {$method} does not exist."); } diff --git a/src/Traits/Sizable.php b/src/Traits/Sizable.php index 7801d611..8eb21faf 100644 --- a/src/Traits/Sizable.php +++ b/src/Traits/Sizable.php @@ -11,7 +11,7 @@ trait Sizable { /** - * The size of the alert + * The size of the alert. */ protected string $size = 'medium'; @@ -66,7 +66,7 @@ public function fullscreen(): self } /** - * Set modal size + * Set modal size. * * @throws Exception */ @@ -75,7 +75,7 @@ public function size(string $size): self $method = Str::camel($size); // check if function exists - if (! method_exists($this, $method)) { + if (!method_exists($this, $method)) { throw new Exception("Size {$method} is not supported."); } @@ -83,7 +83,7 @@ public function size(string $size): self } /** - * Get the size of the alert + * Get the size of the alert. */ public function getSize(): string { diff --git a/src/Traits/WithButton.php b/src/Traits/WithButton.php index 0ce38bdb..a337bd50 100644 --- a/src/Traits/WithButton.php +++ b/src/Traits/WithButton.php @@ -38,7 +38,7 @@ public function cancelButton(): ?Button public function customButtons(): Collection { return $this->getButtons() - ->filter(fn ($button) => ! in_array($button->getName(), ['action', 'cancel'])); + ->filter(fn ($button) => !in_array($button->getName(), ['action', 'cancel'])); } /** @@ -77,7 +77,7 @@ public function button( $button = new Button($name, $label, $link, $attributes); if (empty($this->buttons)) { - $this->buttons = new Collection; + $this->buttons = new Collection(); } $this->buttons->push($button); @@ -108,7 +108,7 @@ public function buttons(array $buttons): self public function getButtons(): Collection { if (empty($this->buttons)) { - return new Collection; + return new Collection(); } return $this->buttons; diff --git a/src/Traits/WithTitle.php b/src/Traits/WithTitle.php index 028c16a9..138077d9 100644 --- a/src/Traits/WithTitle.php +++ b/src/Traits/WithTitle.php @@ -29,6 +29,6 @@ public function getTitle(): ?string public function hasTitle(): bool { - return ! is_null($this->title); + return !is_null($this->title); } } diff --git a/src/Traits/WithView.php b/src/Traits/WithView.php index 3e4e126c..c53622b6 100644 --- a/src/Traits/WithView.php +++ b/src/Traits/WithView.php @@ -62,6 +62,6 @@ public function getView(): ?string */ public function hasView(): bool { - return ! is_null($this->view); + return !is_null($this->view); } } diff --git a/src/Types/Field.php b/src/Types/Field.php index 8b949a3e..27d83e37 100644 --- a/src/Types/Field.php +++ b/src/Types/Field.php @@ -75,13 +75,13 @@ public function getTag(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'name' => $this->getName(), - 'tag' => $this->getTag(), + 'type' => $this->key(), + 'name' => $this->getName(), + 'tag' => $this->getTag(), 'named_tag' => $this->getNamedTag(), - 'level' => $this->getLevel(), - 'message' => $this->getMessage(), - 'timeout' => $this->getTimeout(), + 'level' => $this->getLevel(), + 'message' => $this->getMessage(), + 'timeout' => $this->getTimeout(), ]); } diff --git a/src/Types/Message.php b/src/Types/Message.php index a5855702..943c207f 100644 --- a/src/Types/Message.php +++ b/src/Types/Message.php @@ -70,14 +70,14 @@ public function getLevel(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'tag' => $this->getTag(), - 'level' => $this->getLevel(), - 'message' => $this->getMessage(), - 'title' => $this->getTitle(), - 'timeout' => $this->getTimeout(), + 'type' => $this->key(), + 'tag' => $this->getTag(), + 'level' => $this->getLevel(), + 'message' => $this->getMessage(), + 'title' => $this->getTitle(), + 'timeout' => $this->getTimeout(), 'closable' => $this->isClosable(), - 'sticky' => $this->isSticky(), + 'sticky' => $this->isSticky(), ]); } diff --git a/src/Types/Modal.php b/src/Types/Modal.php index f35cf608..a3db9663 100644 --- a/src/Types/Modal.php +++ b/src/Types/Modal.php @@ -62,17 +62,17 @@ public function key(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'level' => $this->getLevel(), - 'title' => $this->getTitle(), - 'message' => $this->getMessage(), - 'tag' => $this->getTag(), - 'size' => $this->getSize(), - 'timeout' => $this->getTimeout(), + 'type' => $this->key(), + 'level' => $this->getLevel(), + 'title' => $this->getTitle(), + 'message' => $this->getMessage(), + 'tag' => $this->getTag(), + 'size' => $this->getSize(), + 'timeout' => $this->getTimeout(), 'scrollable' => $this->isScrollable(), - 'closable' => $this->isClosable(), - 'view' => $this->getView(), - 'buttons' => $this->buttonsToArray(), + 'closable' => $this->isClosable(), + 'view' => $this->getView(), + 'buttons' => $this->buttonsToArray(), ]); } @@ -92,7 +92,7 @@ public static function fill(array $alert): AlertInterface $modal->buttons($alert['buttons'] ?? []); foreach (['tag', 'size', 'level', 'title', 'view'] as $property) { - if (! empty($alert[$property])) { + if (!empty($alert[$property])) { $method = $property === 'view' ? 'setView' : $property; $modal->$method($alert[$property]); } diff --git a/src/Types/Notify.php b/src/Types/Notify.php index 776e3c1e..8f7d494c 100644 --- a/src/Types/Notify.php +++ b/src/Types/Notify.php @@ -73,16 +73,16 @@ public function key(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'title' => $this->getTitle(), - 'timeout' => $this->getTimeout(), - 'message' => $this->getMessage(), - 'tag' => $this->getTag(), - 'id_tag' => $this->getIdTag(), - 'level' => $this->getLevel(), + 'type' => $this->key(), + 'title' => $this->getTitle(), + 'timeout' => $this->getTimeout(), + 'message' => $this->getMessage(), + 'tag' => $this->getTag(), + 'id_tag' => $this->getIdTag(), + 'level' => $this->getLevel(), 'position' => $this->getPosition(), 'closable' => $this->isClosable(), - 'buttons' => $this->buttonsToArray(), + 'buttons' => $this->buttonsToArray(), ]); } diff --git a/src/Types/Toastr.php b/src/Types/Toastr.php index 2b0de966..608c125a 100644 --- a/src/Types/Toastr.php +++ b/src/Types/Toastr.php @@ -67,12 +67,12 @@ public function key(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'title' => $this->getTitle(), - 'timeout' => $this->getTimeout(), - 'message' => $this->getMessage(), - 'tag' => $this->getTag(), - 'level' => $this->getLevel(), + 'type' => $this->key(), + 'title' => $this->getTitle(), + 'timeout' => $this->getTimeout(), + 'message' => $this->getMessage(), + 'tag' => $this->getTag(), + 'level' => $this->getLevel(), 'position' => $this->getPosition(), 'closable' => $this->isClosable(), ]); diff --git a/src/Types/ToastrClassic.php b/src/Types/ToastrClassic.php index 335cd7c0..5874b8d2 100644 --- a/src/Types/ToastrClassic.php +++ b/src/Types/ToastrClassic.php @@ -67,12 +67,12 @@ public function key(): string public function toArray(): array { return array_merge(parent::toArray(), [ - 'type' => $this->key(), - 'title' => $this->getTitle(), - 'timeout' => $this->getTimeout(), - 'message' => $this->getMessage(), - 'tag' => $this->getTag(), - 'level' => $this->getLevel(), + 'type' => $this->key(), + 'title' => $this->getTitle(), + 'timeout' => $this->getTimeout(), + 'message' => $this->getMessage(), + 'tag' => $this->getTag(), + 'level' => $this->getLevel(), 'position' => $this->getPosition(), 'closable' => $this->isClosable(), ]); diff --git a/tests/TestCase.php b/tests/TestCase.php index 6ce73b92..a624d8a0 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -24,7 +24,8 @@ protected function getPackageProviders($app): array /** * Override application aliases. * - * @param Application $app + * @param Application $app + * * @return array> */ protected function getPackageAliases($app): array diff --git a/tests/Unit/Component/ButtonTest.php b/tests/Unit/Component/ButtonTest.php index 56b0a960..c7f722d8 100644 --- a/tests/Unit/Component/ButtonTest.php +++ b/tests/Unit/Component/ButtonTest.php @@ -41,10 +41,10 @@ $button = new Button('submit', 'Submit Form', '/submit', ['class' => 'btn-submit']); $expected = [ - 'id' => $button->getId(), - 'name' => 'submit', - 'label' => 'Submit Form', - 'link' => '/submit', + 'id' => $button->getId(), + 'name' => 'submit', + 'label' => 'Submit Form', + 'link' => '/submit', 'attributes' => ['class' => 'btn-submit'], ]; @@ -53,9 +53,9 @@ it('can fill a button from an array', function () { $data = [ - 'name' => 'delete', - 'label' => 'Delete Item', - 'link' => '/delete', + 'name' => 'delete', + 'label' => 'Delete Item', + 'link' => '/delete', 'attributes' => ['id' => 'btn-123', 'class' => 'btn-danger'], ]; diff --git a/tests/Unit/Factory/AlertFactoryTest.php b/tests/Unit/Factory/AlertFactoryTest.php index 9d598a09..b5e13fc9 100644 --- a/tests/Unit/Factory/AlertFactoryTest.php +++ b/tests/Unit/Factory/AlertFactoryTest.php @@ -13,11 +13,11 @@ it('creates an alert using makeFromArray()', function () { $alert = AlertFactory::makeFromArray([ - 'id' => 1, - 'title' => 'Test Alert', - 'level' => 'info', - 'tag' => 'default', - 'type' => 'message', + 'id' => 1, + 'title' => 'Test Alert', + 'level' => 'info', + 'tag' => 'default', + 'type' => 'message', 'message' => 'Hello World', ]); diff --git a/tests/Unit/Foundation/AbstractAlertTest.php b/tests/Unit/Foundation/AbstractAlertTest.php index 5a09d2c3..047794ad 100644 --- a/tests/Unit/Foundation/AbstractAlertTest.php +++ b/tests/Unit/Foundation/AbstractAlertTest.php @@ -10,8 +10,7 @@ }); it('can auto-set and retrieve ID', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public string $message = 'Test Alert'; public function key(): string @@ -26,7 +25,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; @@ -39,8 +38,7 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'auto-set-id'); it('can manually set ID', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public string $message = 'Test Alert'; public function key(): string @@ -55,7 +53,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; @@ -70,8 +68,7 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'manual-set-id'); it('flashes alert to session if id and message are set', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public string $message = 'Hello session'; public function key(): string @@ -86,7 +83,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; @@ -101,8 +98,7 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'flash-session'); it('does not flash if message is empty', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public function key(): string { return 'session_alert'; @@ -115,7 +111,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? ''; @@ -130,8 +126,7 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'no-flash-empty-message'); it('can forget session key', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public string $message = 'Forget me'; public function key(): string @@ -146,7 +141,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; @@ -165,8 +160,7 @@ public static function fill(array $alert): AlertInterface })->group('alert', 'abstract-alert', 'forget-session'); it('can convert to array and json', function () { - $alert = new class extends AbstractAlert - { + $alert = new class() extends AbstractAlert { public string $message = 'Format test'; public function key(): string @@ -181,7 +175,7 @@ public function getTag(): string public static function fill(array $alert): AlertInterface { - $instance = new self; + $instance = new self(); $instance->id($alert['id'] ?? 'default-id'); $instance->message = $alert['message'] ?? 'Default message'; diff --git a/tests/Unit/Helpers/AttributeTest.php b/tests/Unit/Helpers/AttributeTest.php index da5fd972..925c2ed9 100644 --- a/tests/Unit/Helpers/AttributeTest.php +++ b/tests/Unit/Helpers/AttributeTest.php @@ -3,9 +3,8 @@ use Digitlimit\Alert\Helpers\Attribute; it('can generate html element attribute from an array', function () { - $attributesString = Attribute::toString([ - 'id' => 'alert-id', + 'id' => 'alert-id', 'class' => 'hover:underline to-pink-500', ]); diff --git a/tests/Unit/Helpers/ThemeTest.php b/tests/Unit/Helpers/ThemeTest.php index 5b68f209..a0e8c741 100644 --- a/tests/Unit/Helpers/ThemeTest.php +++ b/tests/Unit/Helpers/ThemeTest.php @@ -10,7 +10,6 @@ expect($theme) ->toEqual('tailwind') ->and(Theme::name())->toEqual('tailwind'); - })->group('theme', 'helpers', 'theme-name'); it('can get all themes', function () { @@ -21,7 +20,6 @@ ->not()->toBeEmpty() ->toBeArray() ->toEqual(Theme::all()); - })->group('theme', 'helpers', 'theme-all'); it('can throw exception if theme is not found', function () { @@ -43,5 +41,4 @@ ->toEqual('tailwind') ->and(Theme::theme()) ->toBeInstanceOf(ThemeInterface::class); - })->group('theme', 'helpers', 'theme-instance'); diff --git a/tests/Unit/Icons/ErrorTest.php b/tests/Unit/Icons/ErrorTest.php index c8650281..6a3d2877 100644 --- a/tests/Unit/Icons/ErrorTest.php +++ b/tests/Unit/Icons/ErrorTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Error; + $component = new Error(); expect($component->isCircled())->toBeTrue(); })->group('icons', 'error-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.error', [], []) ->andReturn('rendered-view'); - $component = new Error; + $component = new Error(); expect($component->render())->toBe('rendered-view'); })->group('icons', 'error-icon', 'view'); diff --git a/tests/Unit/Icons/InfoTest.php b/tests/Unit/Icons/InfoTest.php index 4dc97db2..8af1f11e 100644 --- a/tests/Unit/Icons/InfoTest.php +++ b/tests/Unit/Icons/InfoTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Info; + $component = new Info(); expect($component->isCircled())->toBeTrue(); })->group('icons', 'info-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.info', [], []) ->andReturn('rendered-view'); - $component = new Info; + $component = new Info(); expect($component->render())->toBe('rendered-view'); })->group('icons', 'info-icon', 'view'); diff --git a/tests/Unit/Icons/SuccessTest.php b/tests/Unit/Icons/SuccessTest.php index bd623363..1f894c5e 100644 --- a/tests/Unit/Icons/SuccessTest.php +++ b/tests/Unit/Icons/SuccessTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Success; + $component = new Success(); expect($component->isCircled())->toBeTrue(); })->group('icons', 'success-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.success', [], []) ->andReturn('rendered-view'); - $component = new Success; + $component = new Success(); expect($component->render())->toBe('rendered-view'); })->group('icons', 'success-icon', 'view'); diff --git a/tests/Unit/Icons/WarningTest.php b/tests/Unit/Icons/WarningTest.php index a3c5dfcc..396b88c3 100644 --- a/tests/Unit/Icons/WarningTest.php +++ b/tests/Unit/Icons/WarningTest.php @@ -4,7 +4,7 @@ use Illuminate\Support\Facades\View; it('is circled by default', function () { - $component = new Warning; + $component = new Warning(); expect($component->isCircled())->toBeTrue(); })->group('icons', 'warning-icon'); @@ -15,7 +15,7 @@ ->with('alert::icons.warning', [], []) ->andReturn('rendered-view'); - $component = new Warning; + $component = new Warning(); expect($component->render())->toBe('rendered-view'); })->group('icons', 'warning-icon', 'view'); diff --git a/tests/Unit/Types/FieldTest.php b/tests/Unit/Types/FieldTest.php index a13f8e8e..f7740ab1 100644 --- a/tests/Unit/Types/FieldTest.php +++ b/tests/Unit/Types/FieldTest.php @@ -28,24 +28,24 @@ $array = $alert->toArray(); expect($array)->toMatchArray([ - 'id' => $alert->getId(), - 'type' => 'field', - 'name' => 'email', - 'tag' => 'user', + 'id' => $alert->getId(), + 'type' => 'field', + 'name' => 'email', + 'tag' => 'user', 'named_tag' => 'user.email', - 'level' => 'warning', - 'message' => 'Invalid email', - 'timeout' => 0, + 'level' => 'warning', + 'message' => 'Invalid email', + 'timeout' => 0, ]); })->group('field', 'toArray'); it('can fill a field alert from array', function () { $data = [ - 'id' => 'alert-id', - 'name' => 'password', + 'id' => 'alert-id', + 'name' => 'password', 'message' => 'Password must be at least 6 characters', - 'tag' => 'auth', - 'level' => 'info', + 'tag' => 'auth', + 'level' => 'info', ]; $alert = Field::fill($data); diff --git a/tests/Unit/Types/MessageTest.php b/tests/Unit/Types/MessageTest.php index 4d1f4e89..ff27b34d 100644 --- a/tests/Unit/Types/MessageTest.php +++ b/tests/Unit/Types/MessageTest.php @@ -34,24 +34,24 @@ $array = $alert->toArray(); expect($array)->toMatchArray([ - 'id' => $alert->getId(), - 'type' => 'message', - 'tag' => 'updates', - 'level' => 'success', - 'message' => 'New update available', - 'title' => 'Update', - 'timeout' => 10, + 'id' => $alert->getId(), + 'type' => 'message', + 'tag' => 'updates', + 'level' => 'success', + 'message' => 'New update available', + 'title' => 'Update', + 'timeout' => 10, 'closable' => true, ]); })->group('message', 'toArray'); it('can fill a message alert from array', function () { $data = [ - 'id' => 'alert-msg-1', - 'tag' => 'dashboard', - 'level' => 'warning', - 'message' => 'Please verify your email', - 'title' => 'Verification Needed', + 'id' => 'alert-msg-1', + 'tag' => 'dashboard', + 'level' => 'warning', + 'message' => 'Please verify your email', + 'title' => 'Verification Needed', 'closable' => true, ]; @@ -63,7 +63,6 @@ ->and($alert->getMessage())->toBe('Please verify your email') ->and($alert->getTitle())->toBe('Verification Needed') ->and($alert->isClosable())->toBeTrue(); - })->group('message', 'fill'); it('can flash a normal message to session and dispatch event', function () { diff --git a/tests/Unit/Types/ModalTest.php b/tests/Unit/Types/ModalTest.php index 564c612e..98a54853 100644 --- a/tests/Unit/Types/ModalTest.php +++ b/tests/Unit/Types/ModalTest.php @@ -44,30 +44,30 @@ $array = $alert->toArray(); expect($array)->toMatchArray([ - 'id' => $alert->getId(), - 'type' => 'modal', - 'level' => 'info', - 'title' => 'Confirm Action', - 'message' => 'Modal Message', - 'tag' => 'confirm', - 'size' => 'medium', - 'timeout' => 30, + 'id' => $alert->getId(), + 'type' => 'modal', + 'level' => 'info', + 'title' => 'Confirm Action', + 'message' => 'Modal Message', + 'tag' => 'confirm', + 'size' => 'medium', + 'timeout' => 30, 'scrollable' => true, - 'closable' => true, - 'view' => 'modals.confirm', - 'buttons' => [ + 'closable' => true, + 'view' => 'modals.confirm', + 'buttons' => [ [ - 'id' => $alert->cancelButton()->getId(), - 'name' => 'cancel', - 'label' => 'Cancel', - 'link' => null, + 'id' => $alert->cancelButton()->getId(), + 'name' => 'cancel', + 'label' => 'Cancel', + 'link' => null, 'attributes' => [], ], [ - 'id' => $alert->customButtons()->first()->getId(), - 'name' => 'confirm', - 'label' => 'Yes, Confirm', - 'link' => null, + 'id' => $alert->customButtons()->first()->getId(), + 'name' => 'confirm', + 'label' => 'Yes, Confirm', + 'link' => null, 'attributes' => [], ], ], @@ -76,16 +76,16 @@ it('can fill a modal alert from an array', function () { $data = [ - 'id' => 'modal-123', - 'message' => 'Do you want to continue?', - 'tag' => 'dialog', - 'level' => 'warning', - 'timeout' => 15, - 'title' => 'Continue?', + 'id' => 'modal-123', + 'message' => 'Do you want to continue?', + 'tag' => 'dialog', + 'level' => 'warning', + 'timeout' => 15, + 'title' => 'Continue?', 'scrollable' => true, - 'closable' => true, - 'view' => 'modals.continue', - 'buttons' => [ + 'closable' => true, + 'view' => 'modals.continue', + 'buttons' => [ ['name' => 'no', 'label' => 'No'], ['name' => 'yes', 'label' => 'Yes'], ], diff --git a/tests/Unit/Types/NotifyTest.php b/tests/Unit/Types/NotifyTest.php index 08589a35..7e02a292 100644 --- a/tests/Unit/Types/NotifyTest.php +++ b/tests/Unit/Types/NotifyTest.php @@ -29,15 +29,15 @@ it('fills from array correctly', function () { $alertData = [ - 'id' => '123', - 'message' => 'Filled message', - 'title' => 'Filled Title', - 'timeout' => 5000, - 'tag' => 'filled-tag', - 'level' => 'warning', + 'id' => '123', + 'message' => 'Filled message', + 'title' => 'Filled Title', + 'timeout' => 5000, + 'tag' => 'filled-tag', + 'level' => 'warning', 'position' => 'top-right', 'closable' => true, - 'buttons' => [], + 'buttons' => [], ]; $notify = Notify::fill($alertData); diff --git a/tests/Unit/Types/ToastrTest.php b/tests/Unit/Types/ToastrTest.php index 5476338b..725ba94d 100644 --- a/tests/Unit/Types/ToastrTest.php +++ b/tests/Unit/Types/ToastrTest.php @@ -26,12 +26,12 @@ $array = $toastr->toArray(); expect($array)->toMatchArray([ - 'type' => 'toastr', - 'title' => 'Test Title', - 'timeout' => 3000, - 'message' => 'Test message', - 'tag' => 'test-tag', - 'level' => 'success', + 'type' => 'toastr', + 'title' => 'Test Title', + 'timeout' => 3000, + 'message' => 'Test message', + 'tag' => 'test-tag', + 'level' => 'success', 'position' => 'top-right', 'closable' => true, ]); @@ -39,12 +39,12 @@ it('fills a toastr alert from an array', function () { $alertArray = [ - 'id' => '123', - 'message' => 'Filled message', - 'title' => 'Filled Title', - 'timeout' => 5000, - 'tag' => 'filled-tag', - 'level' => 'error', + 'id' => '123', + 'message' => 'Filled message', + 'title' => 'Filled Title', + 'timeout' => 5000, + 'tag' => 'filled-tag', + 'level' => 'error', 'position' => 'bottom-left', 'closable' => false, ]; diff --git a/workbench/app/Models/User.php b/workbench/app/Models/User.php index 6bd3a59e..af6cac87 100644 --- a/workbench/app/Models/User.php +++ b/workbench/app/Models/User.php @@ -9,7 +9,8 @@ class User extends Authenticatable { - use HasFactory, Notifiable; + use HasFactory; + use Notifiable; /** * The attributes that are mass assignable. @@ -39,6 +40,6 @@ class User extends Authenticatable */ protected $casts = [ 'email_verified_at' => 'datetime', - 'password' => 'hashed', + 'password' => 'hashed', ]; } diff --git a/workbench/database/factories/UserFactory.php b/workbench/database/factories/UserFactory.php index 636b6ea1..f812df7c 100644 --- a/workbench/database/factories/UserFactory.php +++ b/workbench/database/factories/UserFactory.php @@ -34,11 +34,11 @@ class UserFactory extends Factory public function definition(): array { return [ - 'name' => fake()->name(), - 'email' => fake()->unique()->safeEmail(), + 'name' => fake()->name(), + 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), - 'password' => static::$password ??= Hash::make('password'), - 'remember_token' => Str::random(10), + 'password' => static::$password ??= Hash::make('password'), + 'remember_token' => Str::random(10), ]; } diff --git a/workbench/database/seeders/DatabaseSeeder.php b/workbench/database/seeders/DatabaseSeeder.php index 88915fdb..5a18b689 100644 --- a/workbench/database/seeders/DatabaseSeeder.php +++ b/workbench/database/seeders/DatabaseSeeder.php @@ -16,7 +16,7 @@ public function run(): void // UserFactory::new()->times(10)->create(); UserFactory::new()->create([ - 'name' => 'Test User', + 'name' => 'Test User', 'email' => 'test@example.com', ]); } From f404bf84923c977e9062b076cdb3c0fbd05b48f7 Mon Sep 17 00:00:00 2001 From: Emeka Mbah Date: Sun, 20 Apr 2025 16:44:03 +0100 Subject: [PATCH 8/8] feat: support php8.2 and greater --- .github/workflows/alert.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/alert.yml b/.github/workflows/alert.yml index 6630f3c8..e806cf9e 100644 --- a/.github/workflows/alert.yml +++ b/.github/workflows/alert.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: - php-version: ['8.1', '8.2'] + php-version: ['8.2'] steps: - uses: actions/checkout@v3