Skip to content

Commit 7971f45

Browse files
committed
PhpNamespace::simplifyType() supports generics like Foo<A, B>
1 parent 224209a commit 7971f45

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/PhpGenerator/PhpNamespace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public function unresolveName(string $name): string
141141

142142
public function simplifyType(string $type): string
143143
{
144-
return preg_replace_callback('~[^|&?]+~', function ($m) { return $this->simplifyName($m[0]); }, $type);
144+
return preg_replace_callback('~[\w\x7f-\xff\\\\]+~', function ($m) { return $this->simplifyName($m[0]); }, $type);
145145
}
146146

147147

tests/PhpGenerator/PhpNamespace.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ Assert::same('\Bar', $namespace->simplifyName('Bar'));
5252
Assert::same('C', $namespace->simplifyName('\bar\C'));
5353
Assert::same('C', $namespace->simplifyName('bar\C'));
5454
Assert::same('C\D', $namespace->simplifyName('Bar\C\D'));
55+
Assert::same('A<C, C\D>', $namespace->simplifyType('foo\A<\bar\C, Bar\C\D>'));
56+
Assert::same('žluťoučký', $namespace->simplifyType('foo\žluťoučký'));
5557

5658
foreach (['String', 'string', 'int', 'float', 'bool', 'array', 'callable', 'self', 'parent', ''] as $type) {
5759
Assert::same($type, $namespace->simplifyName($type));

0 commit comments

Comments
 (0)