Skip to content

Commit 7924e1d

Browse files
committed
Increase coverage
1 parent 8ba1861 commit 7924e1d

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

src/Validator/InputValidator.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,15 +152,12 @@ protected function buildValidationTree(ValidationNode $rootObject, array $fields
152152

153153
if (isset($validation['cascade']) && isset($inputData[$property])) {
154154
$groups = $validation['cascade'];
155-
156-
if ($arg['type'] instanceof Closure) {
157-
$arg['type'] = $arg['type']();
158-
}
155+
$argType = $this->unclosure($arg['type']);
159156

160157
/** @var ObjectType|InputObjectType $type */
161-
$type = Type::getNamedType($arg['type']);
158+
$type = Type::getNamedType($argType);
162159

163-
if (static::isListOfType($arg['type'])) {
160+
if (static::isListOfType($argType)) {
164161
$rootObject->$property = $this->createCollectionNode($inputData[$property], $type, $rootObject);
165162
} else {
166163
$rootObject->$property = $this->createObjectNode($inputData[$property], $type, $rootObject);
@@ -273,10 +270,7 @@ private function applyClassValidation(ObjectMetadata $metadata, array $rules): v
273270
$metadata->addConstraints($linkedMetadata->getConstraints());
274271
break;
275272
case 'constraints':
276-
if ($value instanceof Closure) {
277-
$value = $value();
278-
}
279-
foreach ($value as $constraint) {
273+
foreach ($this->unclosure($value) as $constraint) {
280274
if ($constraint instanceof Constraint) {
281275
$metadata->addConstraint($constraint);
282276
} elseif ($constraint instanceof GroupSequence) {
@@ -311,6 +305,20 @@ public static function normalizeConfig($config): array
311305
return $config;
312306
}
313307

308+
/**
309+
* @param mixed $value
310+
*
311+
* @return mixed
312+
*/
313+
private function unclosure($value)
314+
{
315+
if ($value instanceof Closure) {
316+
return $value();
317+
}
318+
319+
return $value;
320+
}
321+
314322
/**
315323
* @param string|array|null $groups
316324
*

0 commit comments

Comments
 (0)