Skip to content

Commit 9ab6369

Browse files
committed
refactor: only make a deep copy if type coercion is enabled
1 parent b3579d6 commit 9ab6369

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/JsonSchema/Constraints/UndefinedConstraint.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,16 @@ protected function validateOfProperties(&$value, $schema, JsonPointer $path, $i
355355
$allErrors = [];
356356
$matchedSchemas = [];
357357
$startErrors = $this->getErrors();
358+
$coerce = $this->factory->getConfig(self::CHECK_MODE_COERCE_TYPES);
359+
358360
foreach ($schema->oneOf as $oneOf) {
359361
try {
360362
$this->errors = [];
361363

362-
$valueDeepCopy = DeepCopy::copyOf($value);
363-
$this->checkUndefined($valueDeepCopy, $oneOf, $path, $i);
364+
$oneOfValue = $coerce ? DeepCopy::copyOf($value) : $value;
365+
$this->checkUndefined($oneOfValue, $oneOf, $path, $i);
364366
if (count($this->getErrors()) === 0) {
365-
$matchedSchemas[] = ['schema' => $oneOf, 'value' => $valueDeepCopy];
367+
$matchedSchemas[] = ['schema' => $oneOf, 'value' => $oneOfValue];
366368
}
367369
$allErrors = array_merge($allErrors, array_values($this->getErrors()));
368370
} catch (ValidationException $e) {

0 commit comments

Comments
 (0)