Skip to content

Commit 47ec3c7

Browse files
committed
fix: exception instead of php warning
1 parent 05e224b commit 47ec3c7

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*****************************************************************************
4+
*
5+
* PROJECT: MTA PHP SDK
6+
* LICENSE: See LICENSE in the top level directory
7+
* FILE: NotCallableResourceException.php
8+
*
9+
* Multi Theft Auto is available from http://www.multitheftauto.com/
10+
*
11+
*****************************************************************************/
12+
13+
declare(strict_types=1);
14+
15+
namespace MultiTheftAuto\Sdk\Exception;
16+
17+
class NotCallableResourceException extends MessageException
18+
{
19+
protected const EXCEPTION_MESSAGE = 'There was a problem with the request. Ensure that the resource handling the call is running.';
20+
}

src/Transformer/ElementTransformer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace MultiTheftAuto\Sdk\Transformer;
1616

1717
use MultiTheftAuto\Sdk\Factory\ElementFactory;
18+
use MultiTheftAuto\Sdk\Exception\NotCallableResourceException;
1819

1920
abstract class ElementTransformer
2021
{
@@ -29,8 +30,12 @@ public static function fromServer(?string $dataFromServer): ?array
2930

3031
$data = json_decode($dataFromServer);
3132

32-
foreach ($data as &$value) {
33-
ElementTransformer::stringValuesToObjects($value);
33+
if ($data !== NULL) {
34+
foreach ($data as &$value) {
35+
ElementTransformer::stringValuesToObjects($value);
36+
}
37+
} else {
38+
throw new NotCallableResourceException();
3439
}
3540

3641
return $data;

0 commit comments

Comments
 (0)