Skip to content

Commit 5ae2c83

Browse files
committed
Factory: fixed visibility of promoted property
1 parent 9ad7883 commit 5ae2c83

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/PhpGenerator/Factory.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,14 @@ public function fromCallable(callable $from): Method|GlobalFunction|Closure
199199

200200
public function fromParameterReflection(\ReflectionParameter $from): Parameter
201201
{
202-
$param = $from->isPromoted()
203-
? (new PromotedParameter($from->name))->setReadOnly(PHP_VERSION_ID >= 80100 && $from->getDeclaringClass()->getProperty($from->name)->isReadonly())
204-
: new Parameter($from->name);
202+
if ($from->isPromoted()) {
203+
$property = $from->getDeclaringClass()->getProperty($from->name);
204+
$param = (new PromotedParameter($from->name))
205+
->setVisibility($this->getVisibility($property))
206+
->setReadOnly(PHP_VERSION_ID >= 80100 && $property->isReadonly());
207+
} else {
208+
$param = new Parameter($from->name);
209+
}
205210
$param->setReference($from->isPassedByReference());
206211
$param->setType((string) $from->getType());
207212

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class Class12
2828

2929

3030
public function __construct(
31-
public readonly string $foo,
31+
private readonly string $foo,
3232
) {
3333
}
3434
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ readonly class Class13
44

55

66
public function __construct(
7-
public bool $bar = true,
7+
private bool $bar = true,
88
) {
99
}
1010

tests/PhpGenerator/expected/ClassType.from.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ class Class8
111111
{
112112
public function __construct(
113113
public $a,
114-
public string|int $b = 10,
114+
private string|int $b = 10,
115115
$c = null,
116116
) {
117117
}

0 commit comments

Comments
 (0)