Skip to content

Commit

Permalink
Add missing return types and fix code style (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
shuvroroy authored Apr 2, 2021
1 parent 8f1b328 commit 2d86ea0
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 35 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/vendor
.idea
.DS_Store
composer.lock
composer.lock
.phpunit.result.cache
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ class EditUser extends ModalComponent
{
public User $user;

public function mount(User $user) {
public function mount(User $user)
{
$this->user = $user;
}

Expand Down Expand Up @@ -144,7 +145,8 @@ class EditUser extends ModalComponent
{
public User $user;

public function mount(User $user) {
public function mount(User $user)
{
$this->user = $user;
}

Expand Down Expand Up @@ -220,7 +222,8 @@ class DeleteTeam extends ModalComponent
{
public Team $team;

public function mount(Team $team) {
public function mount(Team $team)
{
$this->team = $team;
}

Expand All @@ -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).
Livewire UI is open-sourced software licensed under the [MIT license](LICENSE.md).
2 changes: 1 addition & 1 deletion resources/js/modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ window.LivewireUiModal = () => {
});
}
};
}
}
2 changes: 1 addition & 1 deletion src/Contracts/ModalComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
interface ModalComponent
{

}
}
10 changes: 5 additions & 5 deletions src/LivewireModalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class LivewireModalServiceProvider extends ServiceProvider
{
public static array $scripts = ['modal.js'];

public function boot()
public function boot(): void
{
$this->registerViews();

Expand All @@ -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([
Expand All @@ -44,4 +44,4 @@ private function registerPublishables()
], 'livewire-ui:public');
}
}
}
}
9 changes: 5 additions & 4 deletions src/Modal.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LivewireUI\Modal;

use Exception;
use Illuminate\View\View;
use Livewire\Component;
use ReflectionClass;

Expand All @@ -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);
Expand Down Expand Up @@ -47,8 +48,8 @@ public function getListeners(): array
];
}

public function render()
public function render(): View
{
return view('livewire-ui::modal');
}
}
}
11 changes: 6 additions & 5 deletions src/ModalComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -52,8 +52,9 @@ private function emitModalEvents(array $events): void
if (is_array($event)) {
[$event, $params] = $event;
}

$this->emitTo($component, $event, ...$params ?? []);
}
}
}
}
}
2 changes: 1 addition & 1 deletion tests/Components/DemoModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ public function render()
</div>
blade;
}
}
}
2 changes: 1 addition & 1 deletion tests/Components/InvalidModal.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
class InvalidModal extends Component
{

}
}
13 changes: 6 additions & 7 deletions tests/LivewireModalComponentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,27 @@

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')
->call('closeModal')
->assertEmitted('closeModal', true, 0);
}

public function testModalSkipping()
public function testModalSkipping(): void
{
Livewire::test(DemoModal::class)
->call('skipPreviousModals', 5)
Expand All @@ -36,18 +35,18 @@ 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', [
DemoModal::getName() => ['someEventWithParams', ['param1', 'param2']],
])
->assertEmitted('someEventWithParams', 'param1', 'param2');
}
}
}
4 changes: 2 additions & 2 deletions tests/LivewireModalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testModalReset(): void
->assertSet('components', []);
}

public function testIfExceptionIsThrownIfModalDoesNotImplementContract()
public function testIfExceptionIsThrownIfModalDoesNotImplementContract(): void
{
$component = InvalidModal::class;
$this->expectException(\Exception::class);
Expand All @@ -67,4 +67,4 @@ public function testIfExceptionIsThrownIfModalDoesNotImplementContract()
Livewire::component('invalid-modal', $component);
Livewire::test(Modal::class)->emit('openModal', 'invalid-modal');
}
}
}
6 changes: 3 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

class TestCase extends \Orchestra\Testbench\TestCase
{
protected function getPackageProviders($app)
protected function getPackageProviders($app): array
{
return [
LivewireServiceProvider::class,
LivewireModalServiceProvider::class
];
}

protected function getEnvironmentSetUp($app)
protected function getEnvironmentSetUp($app): void
{
$app['config']->set('app.key', 'base64:z1qfUazFM1lzfPy5sFcm8oykb2pQeS0/wuX79GdL3zI=');
}
}
}

0 comments on commit 2d86ea0

Please sign in to comment.