Skip to content
Merged
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 .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [ '7.3', '7.4','8.0' ]
php: [ '7.3', '7.4', '8.0', '8.1' ]
stability: [ prefer-lowest, prefer-stable ]

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"source": "https://github.com/messagebird/php-rest-api"
},
"require": {
"php": ">=7.3|^8.0",
"php": ">=7.3|~8.0.0|~8.1.0",
"ext-curl": "*",
"ext-json": "*",
"firebase/php-jwt": "^5.4"
},
"require-dev": {
"phpunit/phpunit": "^8.0|^9.0",
"phpunit/phpunit": "^9.5.14",
"vimeo/psalm": "4.18.1"
},
"autoload": {
Expand Down
28 changes: 15 additions & 13 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="autoload.php"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="autoload.php"
>
<testsuites>
<testsuite name="php-rest-api">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<coverage>
<include>
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
</include>
</coverage>
</phpunit>
4 changes: 4 additions & 0 deletions src/MessageBird/Resources/AvailablePhoneNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ public function getList(string $countryCode, array $parameters = [])
*/
private function processRequest(?string $body): Objects\Number
{
if ($body === null) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

try {
$body = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
Expand Down
8 changes: 4 additions & 4 deletions src/MessageBird/Resources/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ public function create($object, ?array $query = null)
*/
public function processRequest(?string $body)
{
try {
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
if ($body === null) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

if ($body === null) {
try {
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

Expand Down
8 changes: 4 additions & 4 deletions src/MessageBird/Resources/Voice/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,17 @@ public function getList($parameters = [])
*/
public function processRequest(?string $body)
{
if ($body === null) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

try {
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');

}

if ($body === null) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

if (empty($body->errors)) {
return $this->object->loadFromArray($body->data[0]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/MessageBird/Resources/Voice/Legs.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ public function getList(string $callId, array $parameters = [])
*/
public function processRequest(?string $body): Objects\Voice\Leg
{
try {
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
if ($body === null) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

if ($body === null) {
try {
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
} catch (\JsonException $e) {
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
}

Expand Down
13 changes: 7 additions & 6 deletions tests/Unit/RequestValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,28 @@ public function __construct($array)
$this->array = $array;
}

function rewind()
function rewind(): void
{
return reset($this->array);
reset($this->array);
}

function current()
function current(): array
{
return [current($this->array)];
}

#[\ReturnTypeWillChange]
function key()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the return type of the interface (which is mixed ) is not compatible with PHP prior to version 8, the attribute is added instead of the correct type.

{
return current($this->array)['name'];
}

function next()
function next(): void
{
return [next($this->array)];
next($this->array);
}

function valid()
function valid(): bool
{
return key($this->array) !== null;
}
Expand Down