Skip to content

Commit 56ced4a

Browse files
authored
Merge pull request #33 from open-code-modeling/0.8.x-merge-up-into-0.9.x_5fada338de0779.06971822
Merge release 0.8.2 into 0.9.x
2 parents 06eeb52 + 3d1016d commit 56ced4a

File tree

7 files changed

+99
-19
lines changed

7 files changed

+99
-19
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,26 @@ All notable changes to this project will be documented in this file, in reverse
2424

2525
- Nothing.
2626

27+
## 0.8.2 - 2020-11-12
28+
29+
30+
-----
31+
32+
### Release Notes for [0.8.2](https://github.com/open-code-modeling/php-code-ast/milestone/12)
33+
34+
0.8.x bugfix release (patch)
35+
36+
### 0.8.2
37+
38+
- Total issues resolved: **2**
39+
- Total pull requests resolved: **0**
40+
- Total contributors: **1**
41+
42+
#### bug
43+
44+
- [32: Fix typed and body detection](https://github.com/open-code-modeling/php-code-ast/issues/32) thanks to @sandrokeil
45+
- [31: Use fluent setter methods for builder classes](https://github.com/open-code-modeling/php-code-ast/issues/31) thanks to @sandrokeil
46+
2747
## 0.8.1 - 2020-11-11
2848

2949

src/Builder/ClassBuilder.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,11 @@ public function getNamespace(): ?string
196196
return $this->namespace;
197197
}
198198

199-
public function setName(?string $name): void
199+
public function setName(?string $name): self
200200
{
201201
$this->name = $name;
202+
203+
return $this;
202204
}
203205

204206
public function getName(): ?string
@@ -211,6 +213,13 @@ public function isStrict(): bool
211213
return $this->strict;
212214
}
213215

216+
public function setTyped(bool $typed): self
217+
{
218+
$this->typed = $typed;
219+
220+
return $this;
221+
}
222+
214223
public function isTyped(): bool
215224
{
216225
return $this->typed;

src/Builder/ClassMethodBuilder.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use PhpParser\NodeTraverser;
2020
use PhpParser\NodeVisitor;
2121
use PhpParser\Parser;
22+
use PhpParser\PrettyPrinter\Standard;
23+
use PhpParser\PrettyPrinterAbstract;
2224

2325
final class ClassMethodBuilder
2426
{
@@ -67,8 +69,12 @@ private function __construct()
6769
{
6870
}
6971

70-
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
7173
{
74+
if (null === $printer) {
75+
$printer = new Standard(['shortArraySyntax' => true]);
76+
}
77+
7278
$self = new self();
7379

7480
$self->name = $node->name->toString();
@@ -81,8 +87,10 @@ public static function fromNode(Node\Stmt\ClassMethod $node): self
8187
$self->parameters[] = ParameterBuilder::fromNode($param);
8288
}
8389

84-
if ($self->returnType !== null) {
85-
$self->typed = true;
90+
$self->typed = $typed;
91+
92+
if (null !== $node->stmts) {
93+
$self->body = $printer->prettyPrint($node->stmts);
8694
}
8795

8896
return $self;
@@ -134,6 +142,13 @@ public function getParameters(): array
134142
return $this->parameters;
135143
}
136144

145+
public function setTyped(bool $typed): self
146+
{
147+
$this->typed = $typed;
148+
149+
return $this;
150+
}
151+
137152
public function isTyped(): bool
138153
{
139154
return $this->typed;
@@ -165,29 +180,35 @@ public function getDocBlockComment(): ?string
165180
return $this->docBlockComment;
166181
}
167182

168-
public function setDocBlockComment(?string $docBlockComment): void
183+
public function setDocBlockComment(?string $docBlockComment): self
169184
{
170185
$this->docBlockComment = $docBlockComment;
186+
187+
return $this;
171188
}
172189

173190
public function getReturnTypeDocBlockHint(): string
174191
{
175192
return $this->returnTypeDocBlockHint;
176193
}
177194

178-
public function setReturnTypeDocBlockHint(?string $typeDocBlockHint): void
195+
public function setReturnTypeDocBlockHint(?string $typeDocBlockHint): self
179196
{
180197
$this->returnTypeDocBlockHint = $typeDocBlockHint;
198+
199+
return $this;
181200
}
182201

183202
public function getDocBlock(): ?DocBlock
184203
{
185204
return $this->docBlock;
186205
}
187206

188-
public function overrideDocBlock(?DocBlock $docBlock): void
207+
public function overrideDocBlock(?DocBlock $docBlock): self
189208
{
190209
$this->docBlock = $docBlock;
210+
211+
return $this;
191212
}
192213

193214
public function setFinal(bool $final): self

src/Builder/ClassPropertyBuilder.php

Lines changed: 18 additions & 8 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
}
@@ -93,6 +90,13 @@ public function getType(): string
9390
return $this->type;
9491
}
9592

93+
public function setTyped(bool $typed): self
94+
{
95+
$this->typed = $typed;
96+
97+
return $this;
98+
}
99+
96100
public function isTyped(): bool
97101
{
98102
return $this->typed;
@@ -124,29 +128,35 @@ public function getDocBlockComment(): ?string
124128
return $this->docBlockComment;
125129
}
126130

127-
public function setDocBlockComment(?string $docBlockComment): void
131+
public function setDocBlockComment(?string $docBlockComment): self
128132
{
129133
$this->docBlockComment = $docBlockComment;
134+
135+
return $this;
130136
}
131137

132138
public function getTypeDocBlockHint(): string
133139
{
134140
return $this->typeDocBlockHint;
135141
}
136142

137-
public function setTypeDocBlockHint(?string $typeDocBlockHint): void
143+
public function setTypeDocBlockHint(?string $typeDocBlockHint): self
138144
{
139145
$this->typeDocBlockHint = $typeDocBlockHint;
146+
147+
return $this;
140148
}
141149

142150
public function getDocBlock(): ?DocBlock
143151
{
144152
return $this->docBlock;
145153
}
146154

147-
public function overrideDocBlock(?DocBlock $docBlock): void
155+
public function overrideDocBlock(?DocBlock $docBlock): self
148156
{
149157
$this->docBlock = $docBlock;
158+
159+
return $this;
150160
}
151161

152162
public function generate(): NodeVisitor

src/Builder/InterfaceBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ public function isStrict(): bool
116116
return $this->strict;
117117
}
118118

119+
public function setTyped(bool $typed): self
120+
{
121+
$this->typed = $typed;
122+
123+
return $this;
124+
}
125+
119126
public function isTyped(): bool
120127
{
121128
return $this->typed;

src/Builder/ParameterBuilder.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,29 +95,42 @@ public function getDefaultValue()
9595
/**
9696
* @param mixed $defaultValue
9797
*/
98-
public function setDefaultValue($defaultValue): void
98+
public function setDefaultValue($defaultValue): self
9999
{
100100
$this->defaultValue = $defaultValue;
101+
102+
return $this;
101103
}
102104

103105
public function isPassedByReference(): bool
104106
{
105107
return $this->passedByReference;
106108
}
107109

108-
public function setPassedByReference(bool $passedByReference): void
110+
public function setPassedByReference(bool $passedByReference): self
109111
{
110112
$this->passedByReference = $passedByReference;
113+
114+
return $this;
111115
}
112116

113117
public function isVariadic(): bool
114118
{
115119
return $this->variadic;
116120
}
117121

118-
public function setVariadic(bool $variadic): void
122+
public function setVariadic(bool $variadic): self
119123
{
120124
$this->variadic = $variadic;
125+
126+
return $this;
127+
}
128+
129+
public function setName(string $name): self
130+
{
131+
$this->name = $name;
132+
133+
return $this;
121134
}
122135

123136
public function getName(): string

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)