From 2d86ea031627e4d8ebdd8d03fb91eb1493bc5dba Mon Sep 17 00:00:00 2001 From: Shuvro Roy Date: Fri, 2 Apr 2021 14:57:36 +0600 Subject: [PATCH] Add missing return types and fix code style (#1) --- .gitignore | 3 ++- README.md | 11 +++++++---- resources/js/modal.js | 2 +- src/Contracts/ModalComponent.php | 2 +- src/LivewireModalServiceProvider.php | 10 +++++----- src/Modal.php | 9 +++++---- src/ModalComponent.php | 11 ++++++----- tests/Components/DemoModal.php | 2 +- tests/Components/InvalidModal.php | 2 +- tests/LivewireModalComponentTest.php | 13 ++++++------- tests/LivewireModalTest.php | 4 ++-- tests/TestCase.php | 6 +++--- 12 files changed, 40 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index 4cbf175..6d7e08a 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ /vendor .idea .DS_Store -composer.lock \ No newline at end of file +composer.lock +.phpunit.result.cache diff --git a/README.md b/README.md index 7e972f2..3728467 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,8 @@ class EditUser extends ModalComponent { public User $user; - public function mount(User $user) { + public function mount(User $user) + { $this->user = $user; } @@ -144,7 +145,8 @@ class EditUser extends ModalComponent { public User $user; - public function mount(User $user) { + public function mount(User $user) + { $this->user = $user; } @@ -220,7 +222,8 @@ class DeleteTeam extends ModalComponent { public Team $team; - public function mount(Team $team) { + public function mount(Team $team) + { $this->team = $team; } @@ -245,4 +248,4 @@ class DeleteTeam extends ModalComponent - [All Contributors](../../contributors) ## License -Livewire UI is open-sourced software licensed under the [MIT license](LICENSE.md). \ No newline at end of file +Livewire UI is open-sourced software licensed under the [MIT license](LICENSE.md). diff --git a/resources/js/modal.js b/resources/js/modal.js index 5ad84b3..ce6f5a4 100644 --- a/resources/js/modal.js +++ b/resources/js/modal.js @@ -87,4 +87,4 @@ window.LivewireUiModal = () => { }); } }; -} \ No newline at end of file +} diff --git a/src/Contracts/ModalComponent.php b/src/Contracts/ModalComponent.php index c212c10..7fba7ae 100644 --- a/src/Contracts/ModalComponent.php +++ b/src/Contracts/ModalComponent.php @@ -5,4 +5,4 @@ interface ModalComponent { -} \ No newline at end of file +} diff --git a/src/LivewireModalServiceProvider.php b/src/LivewireModalServiceProvider.php index 8aa4f5f..f2a0d98 100644 --- a/src/LivewireModalServiceProvider.php +++ b/src/LivewireModalServiceProvider.php @@ -9,7 +9,7 @@ class LivewireModalServiceProvider extends ServiceProvider { public static array $scripts = ['modal.js']; - public function boot() + public function boot(): void { $this->registerViews(); @@ -18,17 +18,17 @@ public function boot() $this->registerComponent(); } - private function registerViews() + private function registerViews(): void { $this->loadViewsFrom(__DIR__.'/../resources/views', 'livewire-ui'); } - private function registerComponent() + private function registerComponent(): void { Livewire::component('livewire-ui-modal', Modal::class); } - private function registerPublishables() + private function registerPublishables(): void { if ($this->app->runningInConsole()) { $this->publishes([ @@ -44,4 +44,4 @@ private function registerPublishables() ], 'livewire-ui:public'); } } -} \ No newline at end of file +} diff --git a/src/Modal.php b/src/Modal.php index 30cbf3c..4d73bbb 100644 --- a/src/Modal.php +++ b/src/Modal.php @@ -3,6 +3,7 @@ namespace LivewireUI\Modal; use Exception; +use Illuminate\View\View; use Livewire\Component; use ReflectionClass; @@ -12,13 +13,13 @@ class Modal extends Component public array $components = []; - public function resetState() + public function resetState(): void { $this->components = []; $this->activeComponent = null; } - public function openModal($component, $componentAttributes = [], $modalAttributes = []) + public function openModal($component, $componentAttributes = [], $modalAttributes = []): void { $requiredInterface = \LivewireUI\Modal\Contracts\ModalComponent::class; $componentClass = app('livewire')->getClass($component); @@ -47,8 +48,8 @@ public function getListeners(): array ]; } - public function render() + public function render(): View { return view('livewire-ui::modal'); } -} \ No newline at end of file +} diff --git a/src/ModalComponent.php b/src/ModalComponent.php index 5ffc0cb..17796e3 100644 --- a/src/ModalComponent.php +++ b/src/ModalComponent.php @@ -11,14 +11,14 @@ abstract class ModalComponent extends Component implements Contract public int $skipModals = 0; - public function skipPreviousModals($count = 1) + public function skipPreviousModals($count = 1): self { $this->skipPreviousModal($count); return $this; } - public function skipPreviousModal($count = 1) + public function skipPreviousModal($count = 1): self { $this->skipModals = $count; @@ -32,12 +32,12 @@ public function forceClose(): self return $this; } - public function closeModal() + public function closeModal(): void { $this->emit('closeModal', $this->forceClose, $this->skipModals); } - public function closeModalWithEvents(array $events) + public function closeModalWithEvents(array $events): void { $this->closeModal(); $this->emitModalEvents($events); @@ -52,8 +52,9 @@ private function emitModalEvents(array $events): void if (is_array($event)) { [$event, $params] = $event; } + $this->emitTo($component, $event, ...$params ?? []); } } } -} \ No newline at end of file +} diff --git a/tests/Components/DemoModal.php b/tests/Components/DemoModal.php index 8ce3a03..407bba2 100644 --- a/tests/Components/DemoModal.php +++ b/tests/Components/DemoModal.php @@ -14,4 +14,4 @@ public function render() blade; } -} \ No newline at end of file +} diff --git a/tests/Components/InvalidModal.php b/tests/Components/InvalidModal.php index 1724fba..1d5ea14 100644 --- a/tests/Components/InvalidModal.php +++ b/tests/Components/InvalidModal.php @@ -7,4 +7,4 @@ class InvalidModal extends Component { -} \ No newline at end of file +} diff --git a/tests/LivewireModalComponentTest.php b/tests/LivewireModalComponentTest.php index c98d7ed..155d57d 100644 --- a/tests/LivewireModalComponentTest.php +++ b/tests/LivewireModalComponentTest.php @@ -2,20 +2,19 @@ namespace LivewireUI\Modal\Tests; - use Livewire\Livewire; use LivewireUI\Modal\Tests\Components\DemoModal; class LivewireModalComponentTest extends TestCase { - public function testCloseModal() + public function testCloseModal(): void { Livewire::test(DemoModal::class) ->call('closeModal') ->assertEmitted('closeModal', false, 0); } - public function testForceCloseModal() + public function testForceCloseModal(): void { Livewire::test(DemoModal::class) ->call('forceClose') @@ -23,7 +22,7 @@ public function testForceCloseModal() ->assertEmitted('closeModal', true, 0); } - public function testModalSkipping() + public function testModalSkipping(): void { Livewire::test(DemoModal::class) ->call('skipPreviousModals', 5) @@ -36,13 +35,13 @@ public function testModalSkipping() ->assertEmitted('closeModal', false, 1); } - public function testModalEventEmitting() + public function testModalEventEmitting(): void { Livewire::test(DemoModal::class) ->call('closeModalWithEvents', [ DemoModal::getName() => 'someEvent', ]) - ->assertEmitted('someEvent'); + ->assertEmitted('someEvent'); Livewire::test(DemoModal::class) ->call('closeModalWithEvents', [ @@ -50,4 +49,4 @@ public function testModalEventEmitting() ]) ->assertEmitted('someEventWithParams', 'param1', 'param2'); } -} \ No newline at end of file +} diff --git a/tests/LivewireModalTest.php b/tests/LivewireModalTest.php index 2f27e59..1cdb62a 100644 --- a/tests/LivewireModalTest.php +++ b/tests/LivewireModalTest.php @@ -58,7 +58,7 @@ public function testModalReset(): void ->assertSet('components', []); } - public function testIfExceptionIsThrownIfModalDoesNotImplementContract() + public function testIfExceptionIsThrownIfModalDoesNotImplementContract(): void { $component = InvalidModal::class; $this->expectException(\Exception::class); @@ -67,4 +67,4 @@ public function testIfExceptionIsThrownIfModalDoesNotImplementContract() Livewire::component('invalid-modal', $component); Livewire::test(Modal::class)->emit('openModal', 'invalid-modal'); } -} \ No newline at end of file +} diff --git a/tests/TestCase.php b/tests/TestCase.php index 2f13660..713ada3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -7,7 +7,7 @@ class TestCase extends \Orchestra\Testbench\TestCase { - protected function getPackageProviders($app) + protected function getPackageProviders($app): array { return [ LivewireServiceProvider::class, @@ -15,8 +15,8 @@ protected function getPackageProviders($app) ]; } - protected function getEnvironmentSetUp($app) + protected function getEnvironmentSetUp($app): void { $app['config']->set('app.key', 'base64:z1qfUazFM1lzfPy5sFcm8oykb2pQeS0/wuX79GdL3zI='); } -} \ No newline at end of file +}