Skip to content

Commit a1d7ae3

Browse files
committed
Fix deprecation: Return types in ClientObjectCollection
PHP 8.1 logs deprecation warnings: > Return type of Office365\Runtime\ClientObjectCollection::getIterator() > should either be compatible with IteratorAggregate::getIterator(): Traversable, > or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress > the notice in vendor/vgrem/php-spo/src/Runtime/ClientObjectCollection.php on line 287 and > Return type of Office365\Runtime\ClientObjectCollection::offsetExists($offset) > should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool and > Return type of Office365\Runtime\ClientObjectCollection::offsetGet($offset) > should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, > or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice and > Return type of Office365\Runtime\ClientObjectCollection::offsetSet($offset, $value) > should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void and > Return type of Office365\Runtime\ClientObjectCollection::offsetUnset($offset) > should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void Those can be fixed by adding return types for getIterator(), offsetExists(), offsetSet() and offsetUnset(). For those, the minimum required PHP version needs to be raised to PHP 7.1, since the "void" return type only exists in there. The return type for offsetGet() is "mixed", which cannot be expressed in PHP 7.x, only PHP 8.0 and later. I decided to use the "#[\ReturnTypeWillChange]" annotation so the lib can stay compatible with PHP 7. Related: #293
1 parent 1a16d48 commit a1d7ae3

2 files changed

Lines changed: 7 additions & 6 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"license": "MIT",
1919
"require": {
20-
"php": ">=5.5",
20+
"php": ">=7.1",
2121
"ext-curl": "*",
2222
"ext-json": "*",
2323
"ext-simplexml": "*",

src/Runtime/ClientObjectCollection.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,10 @@ function setProperty($index, $value, $persistChanges = true)
281281

282282

283283
/**
284-
* @return Generator|Traversable
284+
* @return Traversable
285285
* @throws Exception
286286
*/
287-
public function getIterator()
287+
public function getIterator(): Traversable
288288
{
289289
/** @var ClientObject $item */
290290
foreach ($this->data as $index => $item) {
@@ -321,11 +321,12 @@ private function getNextItems(){
321321
* @return boolean
322322
* @abstracting ArrayAccess
323323
*/
324-
public function offsetExists($offset)
324+
public function offsetExists($offset): bool
325325
{
326326
return isset($this->data[$offset]);
327327
}
328328

329+
#[\ReturnTypeWillChange]
329330
/**
330331
* Returns the value at specified offset
331332
*
@@ -348,7 +349,7 @@ public function offsetGet($offset)
348349
* @access public
349350
* @abstracting ArrayAccess
350351
*/
351-
public function offsetSet($offset, $value)
352+
public function offsetSet($offset, $value): void
352353
{
353354
if (is_null($offset)) {
354355
$this->data[] = $value;
@@ -364,7 +365,7 @@ public function offsetSet($offset, $value)
364365
* @access public
365366
* @abstracting ArrayAccess
366367
*/
367-
public function offsetUnset($offset)
368+
public function offsetUnset($offset): void
368369
{
369370
if ($this->offsetExists($offset)) {
370371
unset($this->data[$offset]);

0 commit comments

Comments
 (0)