Skip to content

Commit cdcf0ce

Browse files
committed
Allow static option in ClassMethodBuilder - Close #50
1 parent 17c409e commit cdcf0ce

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/Builder/ClassMethodBuilder.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ final class ClassMethodBuilder
6666
/** @var bool */
6767
private $abstract = false;
6868

69+
/** @var bool */
70+
private $isStatic = false;
71+
6972
private function __construct()
7073
{
7174
}
@@ -279,6 +282,13 @@ public function setAbstract(bool $abstract): self
279282
return $this;
280283
}
281284

285+
public function setStatic(bool $isStatic): self
286+
{
287+
$this->isStatic = $isStatic;
288+
289+
return $this;
290+
}
291+
282292
public function isFinal(): bool
283293
{
284294
return $this->final;
@@ -289,6 +299,11 @@ public function isAbstract(): bool
289299
return $this->abstract;
290300
}
291301

302+
public function isStatic(): bool
303+
{
304+
return $this->isStatic;
305+
}
306+
292307
public function generate(Parser $parser): NodeVisitor
293308
{
294309
return new ClassMethod($this->methodGenerator($parser));
@@ -304,6 +319,9 @@ private function methodGenerator(Parser $parser): MethodGenerator
304319
if ($this->abstract) {
305320
$flags |= MethodGenerator::FLAG_ABSTRACT;
306321
}
322+
if ($this->isStatic) {
323+
$flags |= MethodGenerator::FLAG_STATIC;
324+
}
307325

308326
$body = null;
309327

tests/Builder/ClassMethodBuilderTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function it_generates_method_for_empty_class(): void
4646

4747
$classFactory = ClassBuilder::fromScratch('TestClass', 'My\\Awesome\\Service');
4848
$classFactory->setMethods(
49-
ClassMethodBuilder::fromScratch('setActive')->setReturnType('void')
49+
ClassMethodBuilder::fromScratch('setActive')->setReturnType('void')->setStatic(true)
5050
);
5151
$classFactory->addMethod(
5252
ClassMethodBuilder::fromScratch('doSomething')->setReturnType('void')->setFinal(true)
@@ -62,6 +62,7 @@ public function it_generates_method_for_empty_class(): void
6262
$this->assertSame('setActive', $methods['setActive']->getName());
6363
$this->assertFalse($methods['setActive']->isAbstract());
6464
$this->assertFalse($methods['setActive']->isFinal());
65+
$this->assertTrue($methods['setActive']->isStatic());
6566

6667
$this->assertSame('doSomething', $methods['doSomething']->getName());
6768
$this->assertFalse($methods['doSomething']->isAbstract());
@@ -78,7 +79,7 @@ public function it_generates_method_for_empty_class(): void
7879
7980
class TestClass
8081
{
81-
public function setActive() : void
82+
public static function setActive() : void
8283
{
8384
}
8485
public final function doSomething() : void

0 commit comments

Comments
 (0)