Skip to content

Commit 0a3f47e

Browse files
committed
Fix typed and body detection - Close #32
1 parent 5b8664e commit 0a3f47e

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/Builder/ClassMethodBuilder.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,12 @@ private function __construct()
6969
{
7070
}
7171

72-
public static function fromNode(Node\Stmt\ClassMethod $node): self
72+
public static function fromNode(Node\Stmt\ClassMethod $node, bool $typed = true, PrettyPrinterAbstract $printer = null): self
7373
{
74+
if (null === $printer) {
75+
$printer = new Standard(['shortArraySyntax' => true]);
76+
}
77+
7478
$self = new self();
7579

7680
$self->name = $node->name->toString();
@@ -83,8 +87,10 @@ public static function fromNode(Node\Stmt\ClassMethod $node): self
8387
$self->parameters[] = ParameterBuilder::fromNode($param);
8488
}
8589

86-
if ($self->returnType !== null) {
87-
$self->typed = true;
90+
$self->typed = $typed;
91+
92+
if (null !== $node->stmts) {
93+
$self->body = $printer->prettyPrint($node->stmts);
8894
}
8995

9096
return $self;

src/Builder/ClassPropertyBuilder.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,15 @@ private function __construct()
5656
{
5757
}
5858

59-
public static function fromNode(Node\Stmt\Property $node): self
59+
public static function fromNode(Node\Stmt\Property $node, bool $typed = true): self
6060
{
6161
$self = new self();
6262

6363
$self->name = $node->props[0]->name->name;
6464
$self->defaultValue = $node->props[0]->default;
6565
$self->type = $node->type ? $node->type->toString() : null;
6666
$self->visibility = $node->flags;
67-
68-
if ($self->type !== null) {
69-
$self->typed = true;
70-
}
67+
$self->typed = $typed;
7168

7269
return $self;
7370
}

src/Code/PropertyGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function generate(): Property
165165
),
166166
],
167167
$this->generateAttributes(),
168-
$this->typed ? $this->type->generate() : null
168+
$this->typed && null !== $this->type ? $this->type->generate() : null
169169
);
170170
}
171171

0 commit comments

Comments
 (0)