Skip to content

Commit c798907

Browse files
committed
wip
1 parent de005f6 commit c798907

File tree

6 files changed

+24
-8
lines changed

6 files changed

+24
-8
lines changed

src/Commands/CreateMiddleware.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function getArguments(): array
6363
/**
6464
* Get the console command options.
6565
*
66-
* @return array<int, array<int|string, mixed>>
66+
* @return array<int, array<int, mixed>>
6767
*/
6868
protected function getOptions(): array
6969
{

src/Inertia.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @method static \Inertia\AlwaysProp always(mixed $value)
2121
* @method static \Inertia\MergeProp merge(mixed $value)
2222
* @method static \Inertia\MergeProp deepMerge(mixed $value)
23-
* @method static \Inertia\Response render(string $component, array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed> $props = [])
23+
* @method static \Inertia\Response render(string $component, array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<array-key, mixed>|\Inertia\ProvidesInertiaProperties $props = [])
2424
* @method static \Symfony\Component\HttpFoundation\Response location(string|\Symfony\Component\HttpFoundation\RedirectResponse $url)
2525
* @method static void macro(string $name, object|callable $macro)
2626
* @method static void mixin(object $mixin, bool $replace = true)

src/ProvidesInertiaProperties.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44

55
interface ProvidesInertiaProperties
66
{
7+
/**
8+
* @return array<string, mixed>
9+
*/
710
public function toInertiaProperties(RenderContext $context): iterable;
811
}

src/Response.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class Response implements Responsable
8484
/**
8585
* Create a new Inertia response instance.
8686
*
87-
* @param array<string, mixed> $props
87+
* @param array<int|string, mixed|\Inertia\ProvidesInertiaProperties> $props
8888
*/
8989
public function __construct(
9090
string $component,
@@ -216,6 +216,9 @@ public function resolveProperties(Request $request, array $props): array
216216

217217
/**
218218
* Resolve the ProvidesInertiaProperties props.
219+
*
220+
* @param array<string, mixed> $props
221+
* @return array<string, mixed>
219222
*/
220223
public function resolveInertiaPropsProviders(array $props, Request $request): array
221224
{
@@ -226,10 +229,9 @@ public function resolveInertiaPropsProviders(array $props, Request $request): ar
226229
foreach ($props as $key => $value) {
227230
if (is_numeric($key) && $value instanceof ProvidesInertiaProperties) {
228231
// Pipe into a Collection to leverage Collection::getArrayableItems()
229-
$newProps = array_merge(
230-
$newProps,
231-
collect($value->toInertiaProperties($renderContext))->all()
232-
);
232+
/** @var array<string, mixed> $inertiaProps */
233+
$inertiaProps = collect($value->toInertiaProperties($renderContext))->all();
234+
$newProps = array_merge($newProps, $inertiaProps);
233235
} else {
234236
$newProps[$key] = $value;
235237
}

tests/ResponseFactoryTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,11 +380,14 @@ public function toArray()
380380
]);
381381
}
382382

383-
public function test_will_accept_instances_of_provides_inertia_props()
383+
public function test_will_accept_instances_of_provides_inertia_props(): void
384384
{
385385
Route::middleware([StartSession::class, ExampleMiddleware::class])->get('/', function () {
386386
return Inertia::render('User/Edit', new class implements ProvidesInertiaProperties
387387
{
388+
/**
389+
* @return array<string, mixed>
390+
*/
388391
public function toInertiaProperties(RenderContext $context): iterable
389392
{
390393
return [

tests/ResponseTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,9 @@ public function test_inertia_responsable_objects(): void
857857
'foo' => 'bar',
858858
new class implements ProvidesInertiaProperties
859859
{
860+
/**
861+
* @return \Illuminate\Support\Collection<string, string>
862+
*/
860863
public function toInertiaProperties(RenderContext $context): iterable
861864
{
862865
return collect([
@@ -867,6 +870,7 @@ public function toInertiaProperties(RenderContext $context): iterable
867870
'quux' => 'corge',
868871

869872
], 'app', '123');
873+
/** @var BaseResponse $response */
870874
$response = $response->toResponse($request);
871875
$view = $response->getOriginalContent();
872876
$page = $view->getData()['page'];
@@ -965,12 +969,16 @@ public function test_props_can_be_added_using_the_with_method(): void
965969
->with(['quux' => 'corge'])
966970
->with(new class implements ProvidesInertiaProperties
967971
{
972+
/**
973+
* @return \Illuminate\Support\Collection<string, string>
974+
*/
968975
public function toInertiaProperties(RenderContext $context): iterable
969976
{
970977
return collect(['grault' => 'garply']);
971978
}
972979
});
973980

981+
/** @var BaseResponse $response */
974982
$response = $response->toResponse($request);
975983
$view = $response->getOriginalContent();
976984
$page = $view->getData()['page'];

0 commit comments

Comments
 (0)