Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b8664e

Browse files
Use fluent setter methods for builder classes - Close #31
1 parent e916c83 commit 5b8664e

File tree

5 files changed

+67
-10
lines changed

5 files changed

+67
-10
lines changed

‎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: 18 additions & 3 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
{
@@ -134,6 +136,13 @@ public function getParameters(): array
134136
return $this->parameters;
135137
}
136138

139+
public function setTyped(bool $typed): self
140+
{
141+
$this->typed = $typed;
142+
143+
return $this;
144+
}
145+
137146
public function isTyped(): bool
138147
{
139148
return $this->typed;
@@ -165,29 +174,35 @@ public function getDocBlockComment(): ?string
165174
return $this->docBlockComment;
166175
}
167176

168-
public function setDocBlockComment(?string $docBlockComment): void
177+
public function setDocBlockComment(?string $docBlockComment): self
169178
{
170179
$this->docBlockComment = $docBlockComment;
180+
181+
return $this;
171182
}
172183

173184
public function getReturnTypeDocBlockHint(): string
174185
{
175186
return $this->returnTypeDocBlockHint;
176187
}
177188

178-
public function setReturnTypeDocBlockHint(?string $typeDocBlockHint): void
189+
public function setReturnTypeDocBlockHint(?string $typeDocBlockHint): self
179190
{
180191
$this->returnTypeDocBlockHint = $typeDocBlockHint;
192+
193+
return $this;
181194
}
182195

183196
public function getDocBlock(): ?DocBlock
184197
{
185198
return $this->docBlock;
186199
}
187200

188-
public function overrideDocBlock(?DocBlock $docBlock): void
201+
public function overrideDocBlock(?DocBlock $docBlock): self
189202
{
190203
$this->docBlock = $docBlock;
204+
205+
return $this;
191206
}
192207

193208
public function setFinal(bool $final): self

‎src/Builder/ClassPropertyBuilder.php‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public function getType(): string
9393
return $this->type;
9494
}
9595

96+
public function setTyped(bool $typed): self
97+
{
98+
$this->typed = $typed;
99+
100+
return $this;
101+
}
102+
96103
public function isTyped(): bool
97104
{
98105
return $this->typed;
@@ -124,29 +131,35 @@ public function getDocBlockComment(): ?string
124131
return $this->docBlockComment;
125132
}
126133

127-
public function setDocBlockComment(?string $docBlockComment): void
134+
public function setDocBlockComment(?string $docBlockComment): self
128135
{
129136
$this->docBlockComment = $docBlockComment;
137+
138+
return $this;
130139
}
131140

132141
public function getTypeDocBlockHint(): string
133142
{
134143
return $this->typeDocBlockHint;
135144
}
136145

137-
public function setTypeDocBlockHint(?string $typeDocBlockHint): void
146+
public function setTypeDocBlockHint(?string $typeDocBlockHint): self
138147
{
139148
$this->typeDocBlockHint = $typeDocBlockHint;
149+
150+
return $this;
140151
}
141152

142153
public function getDocBlock(): ?DocBlock
143154
{
144155
return $this->docBlock;
145156
}
146157

147-
public function overrideDocBlock(?DocBlock $docBlock): void
158+
public function overrideDocBlock(?DocBlock $docBlock): self
148159
{
149160
$this->docBlock = $docBlock;
161+
162+
return $this;
150163
}
151164

152165
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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /