Skip to content

Commit d0f40ac

Browse files
committed
Apply changes to avoid PHP deprecations
These changes are introduced to mitigate deprecations from PHP 8.1 and to avoid the lower boundaries test of PHP 8.1 to fail due to PHPUnit resorting to the use of `$GLOBALS`. These changes are introduced before the requirement updates to allow them to be forward and backward compatible.
1 parent 2601a5c commit d0f40ac

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

src/MessageBird/Resources/AvailablePhoneNumbers.php

+4
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ public function getList(string $countryCode, array $parameters = [])
6969
*/
7070
private function processRequest(?string $body): Objects\Number
7171
{
72+
if ($body === null) {
73+
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
74+
}
75+
7276
try {
7377
$body = json_decode($body, true, 512, JSON_THROW_ON_ERROR);
7478
} catch (\JsonException $e) {

src/MessageBird/Resources/Base.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,13 @@ public function create($object, ?array $query = null)
117117
*/
118118
public function processRequest(?string $body)
119119
{
120-
try {
121-
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
122-
} catch (\JsonException $e) {
120+
if ($body === null) {
123121
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
124122
}
125123

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

src/MessageBird/Resources/Voice/Base.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,17 @@ public function getList($parameters = [])
7070
*/
7171
public function processRequest(?string $body)
7272
{
73+
if ($body === null) {
74+
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
75+
}
76+
7377
try {
7478
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
7579
} catch (\JsonException $e) {
7680
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
7781

7882
}
7983

80-
if ($body === null) {
81-
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
82-
}
83-
8484
if (empty($body->errors)) {
8585
return $this->object->loadFromArray($body->data[0]);
8686
}

src/MessageBird/Resources/Voice/Legs.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ public function getList(string $callId, array $parameters = [])
9292
*/
9393
public function processRequest(?string $body): Objects\Voice\Leg
9494
{
95-
try {
96-
$body = json_decode($body, null, 512, \JSON_THROW_ON_ERROR);
97-
} catch (\JsonException $e) {
95+
if ($body === null) {
9896
throw new Exceptions\ServerException('Got an invalid JSON response from the server.');
9997
}
10098

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

tests/Unit/RequestValidatorTest.php

+7-6
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,28 @@ public function __construct($array)
173173
$this->array = $array;
174174
}
175175

176-
function rewind()
176+
function rewind(): void
177177
{
178-
return reset($this->array);
178+
reset($this->array);
179179
}
180180

181-
function current()
181+
function current(): array
182182
{
183183
return [current($this->array)];
184184
}
185185

186+
#[\ReturnTypeWillChange]
186187
function key()
187188
{
188189
return current($this->array)['name'];
189190
}
190191

191-
function next()
192+
function next(): void
192193
{
193-
return [next($this->array)];
194+
next($this->array);
194195
}
195196

196-
function valid()
197+
function valid(): bool
197198
{
198199
return key($this->array) !== null;
199200
}

0 commit comments

Comments
 (0)