Skip to content

Commit

Permalink
fix: check if object, before method_exists
Browse files Browse the repository at this point in the history
  • Loading branch information
the-pulli committed Sep 22, 2023
1 parent aa0eb14 commit c618533
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Macros/MapToCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function __invoke(): Closure
}

if ($deep) {
if (method_exists($ary, 'toArray')) {
if (is_object($ary) && method_exists($ary, 'toArray')) {
$ary = Collection::mapToCollection($ary->toArray(), $deep);
}
}
Expand Down
6 changes: 4 additions & 2 deletions tests/Data/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

readonly class TestObject
{
public function __construct(private string $name, private string $job)
{
public function __construct(
private string $name,
private string $job,
) {
}

public function toArray(): array
Expand Down

0 comments on commit c618533

Please sign in to comment.