Skip to content

Commit

Permalink
Fix description escaping in UsedTraitsRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 25, 2024
1 parent 2bb5282 commit 4ffbb3b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/Rules/Generics/UsedTraitsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,25 @@ public function processNode(Node $node, Scope $scope): array
$description = sprintf('%s %s', $typeDescription, SprintfHelper::escapeFormatString($traitName));
}

$escapedDescription = SprintfHelper::escapeFormatString($description);
$upperCaseDescription = ucfirst($description);
$escapedUpperCaseDescription = SprintfHelper::escapeFormatString($upperCaseDescription);

return $this->genericAncestorsCheck->check(
$node->traits,
array_map(static fn (UsesTag $tag): Type => $tag->getType(), $useTags),
sprintf('%s @use tag contains incompatible type %%s.', ucfirst($description)),
sprintf('%s @use tag contains unresolvable type.', ucfirst($description)),
sprintf('%s has @use tag, but does not use any trait.', ucfirst($description)),
sprintf('The @use tag of %s describes %%s but the %s uses %%s.', $description, $typeDescription),
sprintf('%s @use tag contains incompatible type %%s.', $escapedUpperCaseDescription),
sprintf('%s @use tag contains unresolvable type.', $upperCaseDescription),
sprintf('%s has @use tag, but does not use any trait.', $upperCaseDescription),
sprintf('The @use tag of %s describes %%s but the %s uses %%s.', $escapedDescription, $typeDescription),
'PHPDoc tag @use contains generic type %s but %s %s is not generic.',
'Generic type %s in PHPDoc tag @use does not specify all template types of %s %s: %s',
'Generic type %s in PHPDoc tag @use specifies %d template types, but %s %s supports only %d: %s',
'Type %s in generic type %s in PHPDoc tag @use is not subtype of template type %s of %s %s.',
'Call-site variance annotation of %s in generic type %s in PHPDoc tag @use is not allowed.',
'PHPDoc tag @use has invalid type %s.',
sprintf('%s uses generic trait %%s but does not specify its types: %%s', ucfirst($description)),
sprintf('in used type %%s of %s', $description),
sprintf('%s uses generic trait %%s but does not specify its types: %%s', $escapedUpperCaseDescription),
sprintf('in used type %%s of %s', $escapedDescription),
);
}

Expand Down

0 comments on commit 4ffbb3b

Please sign in to comment.