fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Support;
|
||||
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Support\Collection;
|
||||
use Traversable;
|
||||
use UnexpectedValueException;
|
||||
|
||||
final class StructuredData
|
||||
{
|
||||
/** @return array<array-key, mixed> */
|
||||
public static function collectionItems(mixed $value): array
|
||||
{
|
||||
if ($value instanceof Collection) {
|
||||
return $value->all();
|
||||
}
|
||||
if ($value instanceof Traversable) {
|
||||
return iterator_to_array($value);
|
||||
}
|
||||
if ($value instanceof Arrayable) {
|
||||
return $value->toArray();
|
||||
}
|
||||
if (! is_array($value)) {
|
||||
throw new UnexpectedValueException('Structured data must contain an array; original data has been preserved.');
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user