Skip to content

Commit

Permalink
fixup! Format generic classes in profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
MortalFlesh committed Apr 5, 2022
1 parent fa2c9b9 commit da6bb97
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Resources/views/Profiler/index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
background-color: {{ colors.warning|raw }};
}
small.small {
small.className {
color: gray;
}
</style>
Expand Down
4 changes: 2 additions & 2 deletions src/Service/ClassExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ private function formatGenericClass(string $class): string
try {
if ($this->tryParseClassWithoutGenerics($class, $shortName)) {
return sprintf(
'%s<strong>%s</strong>',
'<small class="className">%s</small><strong>%s</strong>',
$this->replaceOnceFromEnd($shortName, '', $class),
$shortName
);
Expand All @@ -46,7 +46,7 @@ private function formatGenericClass(string $class): string
[$classWithoutGenerics] = explode('<', $class, 2);

return sprintf(
'%s<strong>%s</strong>&lt;%s&gt;',
'<small class="className">%s</small><strong>%s</strong>&lt;%s&gt;',
$this->replaceOnceFromEnd($shortName, '', $classWithoutGenerics),
$shortName,
$generics,
Expand Down
17 changes: 10 additions & 7 deletions tests/Service/ClassExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,33 @@ public function provideClass(): array
// input, expected
'empty' => ['', ''],
'not a class' => ['foo', 'foo'],
'class without generics' => ['Root\Service\ServiceName', 'Root\Service\<strong>ServiceName</strong>'],
'class without generics' => [
'Root\Service\ServiceName',
'<small class="className">Root\Service\</small><strong>ServiceName</strong>',
],
'class with generic parameter' => [
'Root\Service\Generic\ServiceName<T>',
'Root\Service\Generic\<strong>ServiceName</strong>&lt;<strong>T</strong>&gt;',
'<small class="className">Root\Service\Generic\</small><strong>ServiceName</strong>&lt;<small class="className"></small><strong>T</strong>&gt;',
],
'generic class' => [
'Root\Service\Generic\ServiceName<Root\Value\Foo>',
'Root\Service\Generic\<strong>ServiceName</strong>&lt;Root\Value\<strong>Foo</strong>&gt;',
'<small class="className">Root\Service\Generic\</small><strong>ServiceName</strong>&lt;<small class="className">Root\Value\</small><strong>Foo</strong>&gt;',
],
'generic class with multiple generic arguments' => [
'Root\Service\Generic\ServiceName<Root\Value\Foo, Root\Value\Bar>',
'Root\Service\Generic\<strong>ServiceName</strong>&lt;Root\Value\<strong>Foo</strong>, Root\Value\<strong>Bar</strong>&gt;',
'<small class="className">Root\Service\Generic\</small><strong>ServiceName</strong>&lt;<small class="className">Root\Value\</small><strong>Foo</strong>, <small class="className">Root\Value\</small><strong>Bar</strong>&gt;',
],
'generic class with generic class argument' => [
'Root\Service\Generic\ServiceName<Root\Value\Foo<Root\Value\Bar>>',
'Root\Service\Generic\<strong>ServiceName</strong>&lt;Root\Value\<strong>Foo</strong>&lt;Root\Value\<strong>Bar</strong>&gt;&gt;',
'<small class="className">Root\Service\Generic\</small><strong>ServiceName</strong>&lt;<small class="className">Root\Value\</small><strong>Foo</strong>&lt;<small class="className">Root\Value\</small><strong>Bar</strong>&gt;&gt;',
],
'generic class with duplicity in name' => [
'Root\Service\Generic\ServiceName<Root\Value\Foo\Foo>',
'Root\Service\Generic\<strong>ServiceName</strong>&lt;Root\Value\Foo\<strong>Foo</strong>&gt;',
'<small class="className">Root\Service\Generic\</small><strong>ServiceName</strong>&lt;<small class="className">Root\Value\Foo\</small><strong>Foo</strong>&gt;',
],
'generic class with multiple duplicities' => [
'Root\Service\Generic\Foo<Root\Value\Foo<Root\Foo\Foo, Root\Foo\Foo>>',
'Root\Service\Generic\<strong>Foo</strong>&lt;Root\Value\<strong>Foo</strong>&lt;Root\Foo\<strong>Foo</strong>, Root\Foo\<strong>Foo</strong>&gt;&gt;',
'<small class="className">Root\Service\Generic\</small><strong>Foo</strong>&lt;<small class="className">Root\Value\</small><strong>Foo</strong>&lt;<small class="className">Root\Foo\</small><strong>Foo</strong>, <small class="className">Root\Foo\</small><strong>Foo</strong>&gt;&gt;',
],
];
}
Expand Down

0 comments on commit da6bb97

Please sign in to comment.