Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding php81 compatibility #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
}
],
"require": {
"php": ">=5.4",
"php": ">=8.1",
"ext-curl": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {
"phpunit/phpunit": "5.7.*",
"phpunit/phpunit": "9.*",
"ramsey/uuid": "*"
},
"autoload": {
Expand Down
30 changes: 16 additions & 14 deletions lib/Trolley/ResourceCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,19 @@ 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;
}

/**
* returns the first item in the collection
*
* @return mixed
*/
public function firstItem()
public function firstItem(): mixed
{
return $this->_items[0];
return $this->_items[0] ?? false;
}

public function key()
Expand All @@ -79,23 +79,23 @@ public function key()
/**
* advances to the next item in the collection when iterating with foreach
*/
public function next()
public function next(): void
{
++$this->_index;
}

/**
* rewinds the testIterateOverResults collection to the first item when iterating with foreach
*/
public function rewind()
public function rewind(): void
{
$this->_index = 0;
}

/**
* 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) {
Expand All @@ -111,20 +111,22 @@ public function maximumCount()
return $this->_records;
}

private function _getNextPage()
private function _getNextPage(): void
{
$result = $this->_getPage($this->_page + 1);
$this->_items = $result->_items;
$this->_index = 0;
++$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'];
Expand Down