Skip to content

Commit 28929cf

Browse files
Ensure json_decode() errors are caught
1 parent e4712f0 commit 28929cf

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"guzzlehttp/psr7": "^1.6",
1919
"php-http/client-implementation": "^1.0",
2020
"psr/http-client": "^1.0",
21-
"psr/http-message": "^1.0"
21+
"psr/http-message": "^1.0",
22+
"symfony/serializer": "^5.2"
2223
},
2324
"require-dev": {
2425
"php-http/mock-client": "^1.3",

src/Entity/Collection/EntityCollection.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace Hussainweb\DrupalApi\Entity\Collection;
44

5-
use GuzzleHttp\Psr7\Uri;
65
use Psr\Http\Message\ResponseInterface;
6+
use Symfony\Component\Serializer\Encoder\JsonDecode;
7+
use Symfony\Component\Serializer\Encoder\JsonEncoder;
78

89
abstract class EntityCollection implements \Iterator, \Countable
910
{
@@ -31,7 +32,7 @@ final public function __construct($data)
3132
*/
3233
public static function fromResponse(ResponseInterface $response)
3334
{
34-
return new static(json_decode((string) $response->getBody()));
35+
return new static((new JsonDecode())->decode((string) $response->getBody(), JsonEncoder::FORMAT));
3536
}
3637

3738
public function getSelfLink()

0 commit comments

Comments
 (0)