From cf1fd9b14c058a2af88871702a49a3a56b270805 Mon Sep 17 00:00:00 2001 From: Elminson De Oleo Baez Date: Wed, 27 Sep 2023 11:58:41 -0400 Subject: [PATCH] adding php81 compatibility --- README.md | 2 +- composer.json | 4 ++-- lib/Trolley/ResourceCollection.php | 30 ++++++++++++++++-------------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 43bc313..e973938 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ The Trolley PHP SDK provides integration access to the Trolley API. ## Requirements -PHP version >= 5.4.0 is required. +PHP version >= 8.1 is required. The following PHP extensions are required: diff --git a/composer.json b/composer.json index e60a107..8d0e0e8 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ } ], "require": { - "php": ">=5.4", + "php": ">=8.1", "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", @@ -23,7 +23,7 @@ "vlucas/phpdotenv": "^5.5" }, "require-dev": { - "phpunit/phpunit": "5.7.*", + "phpunit/phpunit": "9.*", "ramsey/uuid": "*" }, "autoload": { diff --git a/lib/Trolley/ResourceCollection.php b/lib/Trolley/ResourceCollection.php index 946f837..c4225b7 100644 --- a/lib/Trolley/ResourceCollection.php +++ b/lib/Trolley/ResourceCollection.php @@ -56,9 +56,9 @@ public function __construct($response, $items, $pager) /** * returns the current item when iterating with foreach */ - public function current() + public function current(): mixed { - return $this->_items[$this->_index]; + return $this->_items[$this->_index] ?? false; } /** @@ -66,9 +66,9 @@ public function current() * * @return mixed */ - public function firstItem() + public function firstItem(): mixed { - return $this->_items[0]; + return $this->_items[0] ?? false; } public function key() @@ -79,7 +79,7 @@ public function key() /** * advances to the next item in the collection when iterating with foreach */ - public function next() + public function next(): void { ++$this->_index; } @@ -87,7 +87,7 @@ public function next() /** * rewinds the testIterateOverResults collection to the first item when iterating with foreach */ - public function rewind() + public function rewind(): void { $this->_index = 0; } @@ -95,7 +95,7 @@ public function rewind() /** * returns whether the current item is valid when iterating with foreach */ - public function valid() + public function valid(): bool { if ($this->_index >= count($this->_items)) { if ($this->_page + 1 >= $this->_maxPages) { @@ -111,7 +111,7 @@ public function maximumCount() return $this->_records; } - private function _getNextPage() + private function _getNextPage(): void { $result = $this->_getPage($this->_page + 1); $this->_items = $result->_items; @@ -119,12 +119,14 @@ private function _getNextPage() ++$this->_page; } - /** - * requests the next page of results for the collection - * - * @return void - */ - private function _getPage($page) + /** + * requests the next page of results for the collection + * + * @param $page + * + * @return mixed + */ + private function _getPage($page): mixed { $object = $this->_pager['object']; $method = $this->_pager['method'];