workbench, tests

This commit is contained in:
icefox 2026-02-23 21:09:02 -03:00
parent d83a324eb0
commit 367858c97c
No known key found for this signature in database
27 changed files with 568 additions and 410 deletions

View file

@ -2,24 +2,22 @@
namespace Icefox\DTO\Factories;
use Icefox\DTO\ParameterMeta;
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[]>
* @return array<string,string[]>
*/
public static function rules(ReflectionParameter $parameter, ?Type $type): array
public static function rules(ParameterMeta $parameter, RuleFactory $factory): array
{
if (is_null($type)) {
if (is_null($parameter->tag)) {
return [];
}
$type = $parameter->tag->getType();
if (!$type instanceof Generic) {
return [];
}
@ -27,14 +25,14 @@ class CollectionFactory
$subtypes = $type->getTypes();
if (count($subtypes) == 0) {
return [];
return ['' => ['array']];
}
$subtype = count($subtypes) == 1 ? $subtypes[0] : $subtypes[1];
return array_merge(
return $factory->mergeRules(
['' => ['array']],
RuleFactory::getRulesFromDocBlock($subtype, '.*'),
$factory->getRulesFromDocBlock($subtype, '.*'),
);
}
}