Skip to content

Commit a1f31b4

Browse files
committed
Factory: constant values are tagged for resolving
1 parent 1c15611 commit a1f31b4

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

src/PhpGenerator/Factory.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,9 +219,15 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
219219
$param->setType((string) $from->getType());
220220
}
221221
if ($from->isDefaultValueAvailable()) {
222-
$param->setDefaultValue($from->isDefaultValueConstant()
223-
? new Literal($from->getDefaultValueConstantName())
224-
: $from->getDefaultValue());
222+
if ($from->isDefaultValueConstant()) {
223+
$parts = explode('::', $from->getDefaultValueConstantName());
224+
if (count($parts) > 1) {
225+
$parts[0] = Helpers::tagName($parts[0]);
226+
}
227+
$param->setDefaultValue(new Literal(implode('::', $parts)));
228+
} else {
229+
$param->setDefaultValue($from->getDefaultValue());
230+
}
225231
$param->setNullable($param->isNullable() && $param->getDefaultValue() !== null);
226232
}
227233
$param->setAttributes(self::getAttributes($from));

src/PhpGenerator/Helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public static function formatDocComment(string $content): string
8585

8686
public static function tagName(string $name, string $type = PhpNamespace::NAME_NORMAL): string
8787
{
88-
return "/*($type*/$name";
88+
return isset(self::KEYWORDS[strtolower($name)])
89+
? $name
90+
: "/*($type*/$name";
8991
}
9092

9193

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Class2 extends Class1 implements Interface2
5555
}
5656

5757

58-
private function func4(array $a = [], Class2 $b = null, $c = Abc\Unknown::ABC)
58+
private function func4(array $a = [], Class2 $b = null, $c = Unknown::ABC)
5959
{
6060
}
6161

0 commit comments

Comments
 (0)