Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions packages/http/src/RequestHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,21 @@ public function offsetExists(mixed $offset): bool
{
$offset = strtolower($offset);

return isset($this->headers[$offset]);
return array_key_exists($offset, $this->headers);
}

public function offsetGet(mixed $offset): string
public function offsetGet(mixed $offset): ?string
{
return $this->get((string) $offset);
}

public function get(string $name, ?string $default = null): ?string
{
return $this->headers[strtolower($name)] ?? $default;
$name = strtolower($name);

return array_key_exists($name, $this->headers)
? $this->headers[$name]
: $default;
}

public function has(string $name): bool
Expand Down
1 change: 1 addition & 0 deletions packages/http/tests/GenericRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function test_normalizes_header_access(): void
$this->assertSame($upperCaseValue, $request->headers['uppercase']);
$this->assertSame($upperCaseValue, $request->headers['UPPerCasE']);
$this->assertSame($lowerCaseValue, $request->headers['lowercase']);
$this->assertNull($request->headers['missing']);

$this->assertSame($upperCaseValue, $request->headers->get('UpperCase'));
$this->assertEquals(
Expand Down
6 changes: 5 additions & 1 deletion packages/support/src/Arr/IsIterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public function offsetExists(mixed $offset): bool

public function offsetGet(mixed $offset): mixed
{
return $this->value[$offset] ?? throw new OffsetDidNotExist();
if (! array_key_exists($offset, $this->value)) {
throw new OffsetDidNotExist();
}

return $this->value[$offset];
}

public function offsetSet(mixed $offset, mixed $value): void
Expand Down
8 changes: 8 additions & 0 deletions packages/support/tests/Arr/ImmutableArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ public function test_add_diverse_values(): void
);
}

public function test_null_values_are_accessible_by_offset(): void
{
$collection = new ImmutableArray(['key' => null]);

$this->assertTrue(isset($collection['key']));
$this->assertNull($collection['key']);
}

public function test_remove_with_basic_keys(): void
{
$collection = new ImmutableArray([1, 2, 3]);
Expand Down
12 changes: 8 additions & 4 deletions packages/support/tests/Arr/ToArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ public function test_array_access_and_countable_objects_are_converted_to_arrays(

public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
return array_key_exists($offset, $this->data);
}

public function offsetGet($offset): mixed
{
return $this->data[$offset] ?? null;
return array_key_exists($offset, $this->data)
? $this->data[$offset]
: null;
}

public function offsetSet($offset, $value): void
Expand Down Expand Up @@ -97,12 +99,14 @@ public function test_array_access_without_traversable_or_countable(): void

public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
return array_key_exists($offset, $this->data);
}

public function offsetGet($offset): mixed
{
return $this->data[$offset] ?? null;
return array_key_exists($offset, $this->data)
? $this->data[$offset]
: null;
}

public function offsetSet($offset, $value): void
Expand Down
6 changes: 4 additions & 2 deletions packages/support/tests/Arr/WrapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,14 @@ public function test_array_access_and_countable_objects_are_not_converted_to_arr

public function offsetExists($offset): bool
{
return isset($this->data[$offset]);
return array_key_exists($offset, $this->data);
}

public function offsetGet($offset): mixed
{
return $this->data[$offset] ?? null;
return array_key_exists($offset, $this->data)
? $this->data[$offset]
: null;
}

public function offsetSet($offset, $value): void
Expand Down
6 changes: 4 additions & 2 deletions packages/view/src/Parser/TokenCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@ public function __debugInfo(): array

public function offsetExists(mixed $offset): bool
{
return isset($this->tokens[$offset]);
return array_key_exists($offset, $this->tokens);
}

public function offsetGet(mixed $offset): mixed
{
return $this->tokens[$offset] ?? null;
return array_key_exists($offset, $this->tokens)
? $this->tokens[$offset]
: null;
}

public function offsetSet(mixed $offset, mixed $value): void
Expand Down
9 changes: 9 additions & 0 deletions packages/view/tests/TempestViewParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public function test_parser(): void
HTML, $parsed->compile());
}

public function test_token_collection_treats_null_as_an_existing_offset(): void
{
$tokens = new TokenCollection();
$tokens['nullable'] = null;

$this->assertTrue(isset($tokens['nullable']));
$this->assertNull($tokens['nullable']);
}

public function test_parse_self_closing_tag_with_attributes(): void
{
$tokens = new TokenCollection([
Expand Down
Loading