workbench, tests
This commit is contained in:
parent
d83a324eb0
commit
367858c97c
27 changed files with 568 additions and 410 deletions
|
|
@ -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, '.*'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue