Fix PHP8 behavior of method_exists

This commit is contained in:
John Paul E. Balandan, CPA 2021-02-16 01:45:07 +08:00 committed by GitHub
parent b9f09941c6
commit ebb2b2937f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -429,14 +429,13 @@ class Fabricator
$result[$field] = $this->faker->{$formatter};
}
}
// If no formatters were defined then look for a model fake() method
elseif (method_exists($this->model, 'fake'))
{
$result = $this->model->fake($this->faker);
// This should cover entities
if (method_exists($result, 'toArray'))
if (is_object($result) && method_exists($result, 'toArray'))
{
$result = $result->toArray();
}
@ -446,7 +445,6 @@ class Fabricator
$result = (array) $result;
}
}
// Nothing left to do but give up
else
{