Skip to content

Commit 2ceb700

Browse files
committed
Small refactor for consistency + Extended tests
1 parent 330dcb4 commit 2ceb700

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/Response.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -309,16 +309,16 @@ public function resolveCacheDirections(Request $request): array
309309

310310
public function resolveMergeProps(Request $request): array
311311
{
312-
$resetProps = collect(explode(',', $request->header(Header::RESET, '')));
313-
$onlyProps = collect(explode(',', $request->header(Header::PARTIAL_ONLY, '')))->filter();
314-
$exceptProps = collect(explode(',', $request->header(Header::PARTIAL_EXCEPT, '')));
312+
$resetProps = array_filter(explode(',', $request->header(Header::RESET, '')));
313+
$onlyProps = array_filter(explode(',', $request->header(Header::PARTIAL_ONLY, '')));
314+
$exceptProps = array_filter(explode(',', $request->header(Header::PARTIAL_EXCEPT, '')));
315315

316316
$mergeProps = collect($this->props)
317317
->filter(fn ($prop) => $prop instanceof Mergeable)
318318
->filter(fn ($prop) => $prop->shouldMerge())
319-
->filter(fn ($_, $key) => ! $resetProps->contains($key))
320-
->filter(fn ($_, $key) => $onlyProps->isEmpty() || $onlyProps->contains($key))
321-
->filter(fn ($_, $key) => ! $exceptProps->contains($key));
319+
->reject(fn ($_, $key) => in_array($key, $resetProps))
320+
->filter(fn ($_, $key) => count($onlyProps) === 0 || in_array($key, $onlyProps))
321+
->reject(fn ($_, $key) => in_array($key, $exceptProps));
322322

323323
$deepMergeProps = $mergeProps
324324
->filter(fn ($prop) => $prop->shouldDeepMerge())

tests/ResponseTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ public function test_exclude_merge_props_from_partial_only_response(): void
346346
$this->assertInstanceOf(JsonResponse::class, $response);
347347

348348
$this->assertSame('Jonathan', $props['user']->name);
349+
$this->assertArrayNotHasKey('foo', $props);
350+
$this->assertArrayNotHasKey('bar', $props);
349351
$this->assertFalse(isset($page->mergeProps));
350352
}
351353

@@ -375,6 +377,8 @@ public function test_exclude_merge_props_from_partial_except_response(): void
375377
$this->assertInstanceOf(JsonResponse::class, $response);
376378

377379
$this->assertSame('Jonathan', $props['user']->name);
380+
$this->assertArrayNotHasKey('foo', $props);
381+
$this->assertArrayHasKey('bar', $props);
378382
$this->assertSame(['bar'], $page->mergeProps);
379383
}
380384

0 commit comments

Comments
 (0)