We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4c484a9 commit 69b41f5Copy full SHA for 69b41f5
src/PhpGenerator/Extractor.php
@@ -476,10 +476,12 @@ private function setupFunction(GlobalFunction|Method|PropertyHook $function, Nod
476
foreach ($node->getParams() as $item) {
477
$getVisibility = $this->toVisibility($item->flags);
478
$setVisibility = $this->toSetterVisibility($item->flags);
479
- if ($getVisibility || $setVisibility) {
+ $final = (bool) ($item->flags & Modifiers::FINAL);
480
+ if ($getVisibility || $setVisibility || $final) {
481
$param = $function->addPromotedParameter($item->var->name)
482
->setVisibility($getVisibility, $setVisibility)
- ->setReadonly((bool) ($item->flags & Node\Stmt\Class_::MODIFIER_READONLY));
483
+ ->setReadonly((bool) ($item->flags & Node\Stmt\Class_::MODIFIER_READONLY))
484
+ ->setFinal($final);
485
$this->addHooksToProperty($param, $item);
486
} else {
487
$param = $function->addParameter($item->var->name);
src/PhpGenerator/Factory.php
@@ -211,7 +211,8 @@ public function fromParameterReflection(\ReflectionParameter $from): Parameter
211
$property = $from->getDeclaringClass()->getProperty($from->name);
212
$param = (new PromotedParameter($from->name))
213
->setVisibility($this->getVisibility($property))
214
- ->setReadOnly(PHP_VERSION_ID >= 80100 && $property->isReadonly());
+ ->setReadOnly(PHP_VERSION_ID >= 80100 && $property->isReadonly())
215
+ ->setFinal(PHP_VERSION_ID >= 80500 && $property->isFinal() && !$property->isPrivateSet());
216
$this->addHooks($property, $param);
217
218
$param = new Parameter($from->name);
src/PhpGenerator/Printer.php
@@ -345,7 +345,10 @@ private function formatParameters(Closure|GlobalFunction|Method|PropertyHook $fu
345
$this->printDocComment($param)
346
. ($attrs ? ($multiline ? substr($attrs, 0, -1) . "\n" : $attrs) : '')
347
. ($param instanceof PromotedParameter
348
- ? $this->printPropertyVisibility($param) . ($param->isReadOnly() && $param->getType() ? ' readonly' : '') . ''
+ ? ($param->isFinal() ? 'final ' : '')
349
+ . $this->printPropertyVisibility($param)
350
+ . ($param->isReadOnly() && $param->getType() ? ' readonly' : '')
351
+ . ''
352
: '')
353
. ltrim($this->printType($param->getType(), $param->isNullable()) . '')
354
. ($param->isReference() ? '&' : '')
src/PhpGenerator/Property.php
@@ -28,7 +28,6 @@ final class Property
28
private ?string $type = null;
29
private bool $nullable = false;
30
private bool $initialized = false;
31
- private bool $final = false;
32
private bool $abstract = false;
33
34
@@ -101,19 +100,6 @@ public function isInitialized(): bool
101
100
}
102
103
104
- public function setFinal(bool $state = true): static
105
- {
106
- $this->final = $state;
107
- return $this;
108
- }
109
-
110
111
- public function isFinal(): bool
112
113
- return $this->final;
114
115
116
117
public function setAbstract(bool $state = true): static
118
{
119
$this->abstract = $state;
src/PhpGenerator/Traits/PropertyLike.php
@@ -23,6 +23,7 @@ trait PropertyLike
23
24
/** @var array{'set' => ?string, 'get' => ?string} */
25
private array $visibility = [PropertyAccessMode::Set => null, PropertyAccessMode::Get => null];
26
+ private bool $final = false;
27
private bool $readOnly = false;
/** @var array<string, ?PropertyHook> */
@@ -95,6 +96,19 @@ public function isPrivate(string $mode = PropertyAccessMode::Get): bool
95
96
97
98
99
+ public function setFinal(bool $state = true): static
+ {
+ $this->final = $state;
+ return $this;
+ }
+
+ public function isFinal(): bool
+ return $this->final;
public function setReadOnly(bool $state = true): static
$this->readOnly = $state;
tests/PhpGenerator/PropertyLike.hooks.phpt
@@ -79,6 +79,14 @@ $method->addPromotedParameter('second')
79
->addParameter('value')
80
->setType('string');
81
82
+$method->addPromotedParameter('third')
83
+ ->setPublic()
84
+ ->setProtected('set')
85
+ ->setFinal()
86
+ ->setType('string')
87
+ ->addComment('hello')
88
+ ->addAttribute('Example');
89
90
same(<<<'XX'
91
class Demo
92
@@ -91,6 +99,9 @@ same(<<<'XX'
public string $second {
final set(string $value) => $value;
93
},
+ /** hello */
+ #[Example]
+ final public protected(set) string $third,
94
) {
tests/PhpGenerator/expected/ClassType.from.85.expect
@@ -1,4 +1,10 @@
1
class Class85
2
3
private(set) static string $foo;
4
5
6
+ public function __construct(
7
+ final public $final,
8
+ ) {
9
10
tests/PhpGenerator/expected/Extractor.classes.85.expect
@@ -7,4 +7,10 @@ namespace Abc;
11
12
+ function __construct(
13
14
15
16
tests/PhpGenerator/fixtures/classes.85.php
@@ -7,4 +7,9 @@
+ final $final,
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments