Skip to content

Commit 5860941

Browse files
authored
Ensure that object class contains path from root namespace (#117)
1 parent 7e1f0c2 commit 5860941

File tree

6 files changed

+35
-3
lines changed

6 files changed

+35
-3
lines changed

src/PhpGenerator/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public function fromPropertyReflection(\ReflectionProperty $from): Property
272272

273273
public function fromObject(object $obj): Literal
274274
{
275-
return new Literal('new ' . $obj::class . '(/* unknown */)');
275+
return new Literal('new \\' . $obj::class . '(/* unknown */)');
276276
}
277277

278278

tests/PhpGenerator/ClassType.from.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ $res[] = ClassType::from(Abc\Class7::class);
2929
$res[] = ClassType::from(Abc\Class8::class);
3030
$res[] = ClassType::from(Abc\Class9::class);
3131
$res[] = ClassType::from(Abc\Class10::class);
32+
$res[] = ClassType::from(Abc\Class11::class);
3233

3334
sameFile(__DIR__ . '/expected/ClassType.from.expect', implode("\n", $res));

tests/PhpGenerator/expected/ClassType.from.81.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[Attr(new Abc\Attr(/* unknown */))]
1+
#[Attr(new \Abc\Attr(/* unknown */))]
22
class Class11
33
{
44
final public const FOO = 10;
@@ -12,7 +12,7 @@ class Class11
1212
}
1313

1414

15-
public function bar($c = new stdClass(/* unknown */))
15+
public function bar($c = new \stdClass(/* unknown */))
1616
{
1717
}
1818
}

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,15 @@ class Class10
152152
{
153153
}
154154
}
155+
156+
class Class11
157+
{
158+
public string|int $prop;
159+
160+
161+
public function test(
162+
Class2 $param = new \Abc\Class2(/* unknown */),
163+
Class3 $param2 = new \Abc\Class3(/* unknown */),
164+
): string|int {
165+
}
166+
}

tests/PhpGenerator/expected/Extractor.classes.expect

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,13 @@ class Class10
162162
{
163163
}
164164
}
165+
166+
class Class11
167+
{
168+
public string|int $prop;
169+
170+
171+
function test(Class2 $param = new Class2(), Class3 $param2 = new Class3()): string|int
172+
{
173+
}
174+
}

tests/PhpGenerator/fixtures/classes.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,12 @@ function test(mixed $param): string|int
174174
{
175175
}
176176
}
177+
178+
class Class11
179+
{
180+
public string|int $prop;
181+
182+
function test(Class2 $param = new Class2(), \Abc\Class3 $param2 = new \Abc\Class3()): string|int
183+
{
184+
}
185+
}

0 commit comments

Comments
 (0)