include missing

This commit is contained in:
icefox 2026-02-18 19:19:07 -03:00
parent 88b5850c32
commit d3e12785bb
No known key found for this signature in database
20 changed files with 584 additions and 4 deletions

View file

@ -0,0 +1,40 @@
<?php
namespace Icefox\DTO\Factories;
use Icefox\DTO\Support\RuleFactory;
use Illuminate\Support\Collection;
use Illuminate\Validation\Rule;
use ReflectionParameter;
use phpDocumentor\Reflection\PseudoTypes\Generic;
use phpDocumentor\Reflection\Type;
class CollectionFactory
{
/**
* @return array<string,string|Rule[]>
*/
public static function rules(ReflectionParameter $parameter, ?Type $type): array
{
if (is_null($type)) {
return [];
}
if (!$type instanceof Generic) {
return [];
}
$subtypes = $type->getTypes();
if (count($subtypes) == 0) {
return [];
}
$subtype = count($subtypes) == 1 ? $subtypes[0] : $subtypes[1];
return array_merge(
['' => ['array']],
RuleFactory::getRulesFromDocBlock($subtype, '.*'),
);
}
}