Skip to content

Commit

Permalink
Check collection type before transforming
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryBarker authored Sep 2, 2024
1 parent fd19290 commit daa86cc
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Forge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use GuzzleHttp\Client as HttpClient;
use Laravel\Forge\Resources\User;
use Exception;

class Forge
{
Expand Down Expand Up @@ -76,6 +77,12 @@ public function __construct($apiKey = null, ?HttpClient $guzzle = null)
*/
protected function transformCollection($collection, $class, $extraData = [])
{
if (!is_array($collection)) {
throw new Exception(
"Unexpected response format. Expected an array, got " . gettype($response)

Check failure on line 82 in src/Forge.php

View workflow job for this annotation

GitHub Actions / tests / Static Analysis

Undefined variable: $response
);
}

return array_map(function ($data) use ($class, $extraData) {
return new $class($data + $extraData, $this);
}, $collection);
Expand Down

0 comments on commit daa86cc

Please sign in to comment.