Skip to content

Commit aebde0c

Browse files
author
symfonyaml
committed
Fix Parser instance + HasNamedArguments
1 parent cc48b32 commit aebde0c

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

src/Symfony/Component/Validator/Constraints/Yaml.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Component\Validator\Constraints;
1313

14+
use Symfony\Component\Validator\Attribute\HasNamedArguments;
1415
use Symfony\Component\Validator\Constraint;
1516
use Symfony\Component\Validator\Exception\LogicException;
1617
use Symfony\Component\Yaml\Parser;
@@ -24,6 +25,7 @@ class Yaml extends Constraint
2425
self::INVALID_YAML_ERROR => 'INVALID_YAML_ERROR',
2526
];
2627

28+
#[HasNamedArguments]
2729
public function __construct(
2830
public string $message = 'This value is not valid YAML.',
2931
public int $flags = 0,

src/Symfony/Component/Validator/Constraints/YamlValidator.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function validate(mixed $value, Constraint $constraint): void
4949
});
5050

5151
try {
52-
$this->getParser()->parse($value, $constraint->flags);
52+
(new Parser())->parse($value, $constraint->flags);
5353
} catch (ParseException $e) {
5454
$this->context->buildViolation($constraint->message)
5555
->setParameter('{{ error }}', $e->getMessage())
@@ -60,9 +60,4 @@ public function validate(mixed $value, Constraint $constraint): void
6060
restore_error_handler();
6161
}
6262
}
63-
64-
private function getParser(): Parser
65-
{
66-
return new Parser();
67-
}
6863
}

0 commit comments

Comments
 (0)