baopham / laravel-dynamodb

Eloquent syntax for DynamoDB
https://packagist.org/packages/baopham/dynamodb
MIT License
490 stars 127 forks source link

[fix] \IteratorAggregate, \ArrayAccess, \Countable compliance for PHP 8.1 #264

Closed dmytro-pro closed 1 year ago

dmytro-pro commented 1 year ago

Hi! On PHP 8.1, \BaoPham\DynamoDb\RawDynamoDbQuery class throws deprecation Notices.

This code

$query = new \BaoPham\DynamoDb\RawDynamoDbQuery('', []);
$var = $query->offsetSet(1, 'test');
$res = $query->offsetGet(1);

Produces this amount of errors:

<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>116</b><br />
<br />
<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::offsetExists($offset) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>59</b><br />
<br />
<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::offsetGet($offset) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>73</b><br />
<br />
<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::offsetSet($offset, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>90</b><br />
<br />
<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::offsetUnset($offset) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>104</b><br />
<br />
<b>Deprecated</b>:  Return type of BaoPham\DynamoDb\RawDynamoDbQuery::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in <b>/app/vendor/baopham/dynamodb/src/RawDynamoDbQuery.php</b> on line <b>130</b><br />

All because of types mismatch concerning these internal PHP interfaces: \IteratorAggregate, \ArrayAccess, \Countable. See https://wiki.php.net/rfc/internal_method_return_types for additional info.

I've made a fix for these issues. I tested it manually - it works. I appreciate if You merge this PR if You are ok with these changes. Thanks!

scrutinizer-notifier commented 1 year ago

The inspection completed: No new issues

nelson6e65 commented 1 year ago

@zorkyy Sorry, I didn't get it before. This was added in #270. Available as v6.3.0.