|
25 | 25 |
|
26 | 26 | final class ClassBuilder implements PhpFile |
27 | 27 | { |
| 28 | + use ReadonlyTrait; |
| 29 | + use TypedTrait; |
| 30 | + use FinalTrait; |
| 31 | + use AbstractTrait; |
| 32 | + use StrictTrait; |
| 33 | + |
28 | 34 | /** @var string|null */ |
29 | 35 | private ?string $namespace = null; |
30 | 36 |
|
31 | 37 | /** @var string|null */ |
32 | 38 | private ?string $name = null; |
33 | 39 |
|
34 | | - /** @var bool */ |
35 | | - private bool $strict = false; |
36 | | - |
37 | | - /** @var bool */ |
38 | | - private bool $typed = true; |
39 | | - |
40 | | - /** @var bool */ |
41 | | - private bool $final = false; |
42 | | - |
43 | | - /** @var bool */ |
44 | | - private bool $abstract = false; |
45 | | - |
46 | 40 | /** @var string|null */ |
47 | 41 | private ?string $extends = null; |
48 | 42 |
|
@@ -104,20 +98,6 @@ public function injectVisitors(NodeTraverser $nodeTraverser, Parser $parser): vo |
104 | 98 | } |
105 | 99 | } |
106 | 100 |
|
107 | | - public function setFinal(bool $final): self |
108 | | - { |
109 | | - $this->final = $final; |
110 | | - |
111 | | - return $this; |
112 | | - } |
113 | | - |
114 | | - public function setAbstract(bool $abstract): self |
115 | | - { |
116 | | - $this->abstract = $abstract; |
117 | | - |
118 | | - return $this; |
119 | | - } |
120 | | - |
121 | 101 | public function setExtends(string $extends): self |
122 | 102 | { |
123 | 103 | $this->extends = $extends; |
@@ -456,40 +436,6 @@ public function getName(): ?string |
456 | 436 | return $this->name; |
457 | 437 | } |
458 | 438 |
|
459 | | - public function setStrict(bool $strict): self |
460 | | - { |
461 | | - $this->strict = $strict; |
462 | | - |
463 | | - return $this; |
464 | | - } |
465 | | - |
466 | | - public function isStrict(): bool |
467 | | - { |
468 | | - return $this->strict; |
469 | | - } |
470 | | - |
471 | | - public function setTyped(bool $typed): self |
472 | | - { |
473 | | - $this->typed = $typed; |
474 | | - |
475 | | - return $this; |
476 | | - } |
477 | | - |
478 | | - public function isTyped(): bool |
479 | | - { |
480 | | - return $this->typed; |
481 | | - } |
482 | | - |
483 | | - public function isFinal(): bool |
484 | | - { |
485 | | - return $this->final; |
486 | | - } |
487 | | - |
488 | | - public function isAbstract(): bool |
489 | | - { |
490 | | - return $this->abstract; |
491 | | - } |
492 | | - |
493 | 439 | public function getExtends(): ?string |
494 | 440 | { |
495 | 441 | return $this->extends; |
@@ -655,8 +601,8 @@ static function (ClassConstBuilder $const) { |
655 | 601 | \array_push( |
656 | 602 | $visitors, |
657 | 603 | ...\array_map( |
658 | | - static function (ClassPropertyBuilder $property) { |
659 | | - return $property->generate(); |
| 604 | + static function (ClassPropertyBuilder $property) use ($parser) { |
| 605 | + return $property->generate($parser); |
660 | 606 | }, |
661 | 607 | \array_values($this->properties) |
662 | 608 | ) |
@@ -706,6 +652,7 @@ private function unpackNode(Node $node): void |
706 | 652 | case $node instanceof Node\Stmt\Class_: |
707 | 653 | $this->name = $node->name->name; |
708 | 654 | $this->final = $node->isFinal(); |
| 655 | + $this->isReadonly = $node->isReadonly(); |
709 | 656 |
|
710 | 657 | if ($node->extends !== null) { |
711 | 658 | $this->extends = $node->extends instanceof Node\Name\FullyQualified |
@@ -759,6 +706,9 @@ private function classGenerator(): ClassGenerator |
759 | 706 | if ($this->abstract) { |
760 | 707 | $flags |= ClassGenerator::FLAG_ABSTRACT; |
761 | 708 | } |
| 709 | + if ($this->isReadonly) { |
| 710 | + $flags |= ClassGenerator::FLAG_READONLY; |
| 711 | + } |
762 | 712 |
|
763 | 713 | return new ClassGenerator($this->name, $flags); |
764 | 714 | } |
|
0 commit comments