Skip to content

Commit

Permalink
Merge pull request #7 from gsteel/offset-get-issues-notice
Browse files Browse the repository at this point in the history
Fix uncaught PHP 8.1 Incompatibility
  • Loading branch information
gsteel authored Feb 18, 2022
2 parents 9d08a8a + 00cf055 commit 63b085d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@
<directory suffix=".php">./src</directory>
</include>
</coverage>

<php>
<ini name="error_reporting" value="E_ALL" />
</php>
</phpunit>
4 changes: 4 additions & 0 deletions src/Postmark/Models/CaseInsensitiveArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use ArrayAccess;
use Iterator;
use ReturnTypeWillChange; // phpcs:ignore

use function array_change_key_case;
use function array_keys;
Expand Down Expand Up @@ -86,6 +87,7 @@ public function offsetUnset($offset): void
*
* @return mixed
*/
#[ReturnTypeWillChange]
public function offsetGet($offset)
{
if (is_string($offset)) {
Expand All @@ -96,6 +98,7 @@ public function offsetGet($offset)
}

/** @return mixed */
#[ReturnTypeWillChange]
public function current()
{
// use "offsetGet" instead of indexes
Expand All @@ -104,6 +107,7 @@ public function current()
}

/** @return array-key */
#[ReturnTypeWillChange]
public function key()
{
return array_keys($this->data)[$this->pointer];
Expand Down
6 changes: 6 additions & 0 deletions tests/Unit/Models/CaseInsensitiveArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ public function testValuesCanBeRetrievedInAnyCase(): void
self::assertSame(1, $data['value']);
}

public function testThatOffsetGetDoesNotIssueANoticeOnPHP81(): void
{
$data = new CaseInsensitiveArray(['hey' => 'there']);
self::assertEquals('there', $data->offsetGet('hey'));
}

public function testValuesCanBeMutatedInACaseInsensitiveWay(): void
{
$data = new CaseInsensitiveArray(['value' => 1]);
Expand Down

0 comments on commit 63b085d

Please sign in to comment.