diff --git a/src/BladeXCompiler.php b/src/BladeXCompiler.php index 3a6fe1d..edafcb9 100644 --- a/src/BladeXCompiler.php +++ b/src/BladeXCompiler.php @@ -89,7 +89,7 @@ protected function componentStartString(BladeXComponent $bladeXComponent, array } if ($bladeXComponent->viewModel) { - $componentAttributeString = " + $componentAttributeString = " array_merge( app(Spatie\BladeX\ContextStack::class)->read(), {$componentAttributeString}, diff --git a/src/BladeXComponent.php b/src/BladeXComponent.php index 41371f0..932f595 100644 --- a/src/BladeXComponent.php +++ b/src/BladeXComponent.php @@ -4,7 +4,6 @@ use Closure; use Illuminate\Contracts\Support\Arrayable; -use Illuminate\Support\Str; use Spatie\BladeX\Exceptions\CouldNotRegisterBladeXComponent; class BladeXComponent @@ -33,7 +32,7 @@ public function __construct(string $bladeViewName, string $name = '') $name = kebab_case(end($baseComponentName)); } - if (!view()->exists($bladeViewName)) { + if (! view()->exists($bladeViewName)) { throw CouldNotRegisterBladeXComponent::viewNotFound($bladeViewName, $name); } @@ -55,11 +54,11 @@ public function viewModel($viewModel) return $this; } - if (!class_exists($viewModel)) { + if (! class_exists($viewModel)) { throw CouldNotRegisterBladeXComponent::viewModelNotFound($this->name, $viewModel); } - if (!is_a($viewModel, Arrayable::class, true)) { + if (! is_a($viewModel, Arrayable::class, true)) { throw CouldNotRegisterBladeXComponent::viewModelNotArrayable($this->name, $viewModel); } diff --git a/tests/Features/ViewModel/ViewModelTest.php b/tests/Features/ViewModel/ViewModelTest.php index 4227db8..41bae84 100644 --- a/tests/Features/ViewModel/ViewModelTest.php +++ b/tests/Features/ViewModel/ViewModelTest.php @@ -7,8 +7,8 @@ use Spatie\Snapshots\MatchesSnapshots; use Spatie\BladeX\Exceptions\CouldNotRegisterBladeXComponent; use Spatie\BladeX\Tests\Features\ViewModel\TestClasses\DummyViewModel; -use Spatie\BladeX\Tests\Features\ViewModel\TestClasses\SelectFieldViewModel; use Spatie\BladeX\Tests\Features\ViewModel\TestClasses\InvalidViewModel; +use Spatie\BladeX\Tests\Features\ViewModel\TestClasses\SelectFieldViewModel; class ViewModelTest extends TestCase { @@ -105,18 +105,18 @@ public function it_can_render_a_component_using_a_view_model() /** @test */ public function it_can_render_a_component_using_a_closure_based_view_model() { - BladeX::component('components.select-field')->viewModel(function( + BladeX::component('components.select-field')->viewModel(function ( string $selected) { - return ['isSelected' => function(string $optionName) use ($selected) { + return ['isSelected' => function (string $optionName) use ($selected) { return $optionName === $selected; }]; }); $this->assertMatchesViewSnapshot('viewModel'); - BladeX::component('components.select-field')->viewModel(function( + BladeX::component('components.select-field')->viewModel(function ( string $selected) { - return ['isSelected' => function(string $optionName) use ($selected) { + return ['isSelected' => function (string $optionName) use ($selected) { return $optionName === $selected; }]; }); @@ -139,6 +139,4 @@ public function it_will_return_an_exception_if_a_view_model_class_does_not_imple BladeX::component('components.select-field')->viewModel(InvalidViewModel::class); } - - }