refactor
This commit is contained in:
parent
367858c97c
commit
6b1a385292
13 changed files with 191 additions and 80 deletions
38
src/CustomHandlers.php
Normal file
38
src/CustomHandlers.php
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?php
|
||||
|
||||
namespace Icefox\DTO;
|
||||
|
||||
use Icefox\DTO\RuleFactory;
|
||||
use phpDocumentor\Reflection\PseudoTypes\Generic;
|
||||
|
||||
class CustomHandlers
|
||||
{
|
||||
/**
|
||||
* @return array<string,string[]>
|
||||
*/
|
||||
public static function CollectionRules(ParameterMeta $parameter, RuleFactory $factory): array
|
||||
{
|
||||
if (is_null($parameter->tag)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$type = $parameter->tag->getType();
|
||||
if (!$type instanceof Generic) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$subtypes = $type->getTypes();
|
||||
|
||||
if (count($subtypes) == 0) {
|
||||
return ['' => ['array']];
|
||||
}
|
||||
|
||||
$subtype = count($subtypes) == 1 ? $subtypes[0] : $subtypes[1];
|
||||
|
||||
return $factory->mergeRules(
|
||||
['' => ['array']],
|
||||
$factory->getRulesFromDocBlock($subtype, '.*'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue