Skip to content

Commit a3441b0

Browse files
committed
tweak
1 parent 27238e6 commit a3441b0

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/Types/Concerns/HasValidation.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ trait HasValidation
2121
*/
2222
public function validate(mixed $value): void
2323
{
24-
$validator = new Validator();
25-
$validator->parser()->setOption('defaultDraft', '2020-12');
26-
$validator->parser()->setOption('decodeContent', true);
24+
$validator = $this->makeValidator();
2725

2826
try {
2927
$result = $validator->validate(
@@ -54,4 +52,18 @@ public function isValid(mixed $value): bool
5452
return false;
5553
}
5654
}
55+
56+
/**
57+
* Create a configured validator instance.
58+
*/
59+
private function makeValidator(): Validator
60+
{
61+
$validator = new Validator();
62+
$parser = $validator->parser();
63+
64+
$parser->setOption('defaultDraft', '2020-12');
65+
$parser->setOption('decodeContent', true);
66+
67+
return $validator;
68+
}
5769
}

0 commit comments

Comments
 (0)