Skip to content

Commit 8234d98

Browse files
mglamanclaude
andcommitted
Fix rule message: yaml_parser_class is no longer a Drupal setting
The actual benefit of Drupal\Component\Serialization\Yaml::decode() over Symfony\Component\Yaml\Yaml::parse() is consistent exception handling (InvalidDataTypeException) and correct parse flags. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 6743975 commit 8234d98

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/Rules/Drupal/SymfonyYamlParseRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
/**
1212
* Detects direct usage of Symfony's YAML parser and suggests the Drupal wrapper.
1313
*
14-
* Drupal\Component\Serialization\Yaml::decode() respects the yaml_parser_class
15-
* setting, allowing sites to override the parser. Using Symfony's class directly
16-
* bypasses that setting.
14+
* Drupal\Component\Serialization\Yaml::decode() should be used instead of
15+
* Symfony\Component\Yaml\Yaml::parse() because it wraps exceptions as
16+
* InvalidDataTypeException and applies consistent parse flags.
1717
*
1818
* @implements Rule<StaticCall>
1919
*/
@@ -45,7 +45,7 @@ public function processNode(Node $node, Scope $scope): array
4545

4646
return [
4747
RuleErrorBuilder::message(
48-
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which respects the yaml_parser_class setting.'
48+
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which handles exceptions consistently and applies the correct parse flags.'
4949
)
5050
->identifier('drupal.symfonyYamlParse')
5151
->build(),

tests/src/Rules/SymfonyYamlParseRuleTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ public function testRule(): void
1818
[__DIR__ . '/data/symfony-yaml-parse.php'],
1919
[
2020
[
21-
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which respects the yaml_parser_class setting.',
21+
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which handles exceptions consistently and applies the correct parse flags.',
2222
6,
2323
],
2424
[
25-
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which respects the yaml_parser_class setting.',
25+
'Avoid calling Symfony\Component\Yaml\Yaml::parse() directly. Use \Drupal\Component\Serialization\Yaml::decode() instead, which handles exceptions consistently and applies the correct parse flags.',
2626
9,
2727
],
2828
]

0 commit comments

Comments
 (0)