Skip to content

Commit 9368e43

Browse files
committed
added Nette\Utils\PhpGenerator\Method::addBody()
1 parent d80f4ca commit 9368e43

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/PhpGenerator/Method.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,15 @@ public function addUse($name)
8383

8484

8585

86+
/** @return Method */
87+
public function addBody($statement, array $args = NULL)
88+
{
89+
$this->body .= (func_num_args() > 1 ? Helpers::formatArgs($statement, $args) : $statement) . "\n";
90+
return $this;
91+
}
92+
93+
94+
8695
public function __call($name, $args)
8796
{
8897
return Nette\ObjectMixin::callProperty($this, $name, $args);

tests/PhpGenerator/PhpGenerator.class.expect

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ abstract final class Example extends ParentClass implements IExample, IOne
3737

3838
protected static function & getSections($mode = self::ORDER)
3939
{
40+
$mode = 123;
4041
return self::$sections;
4142
}
4243

tests/PhpGenerator/PhpGenerator.class.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ $class->addMethod('getSections')
5252
->setStatic(TRUE)
5353
->setVisibility('protected')
5454
->setReturnReference(TRUE)
55-
->setBody('return self::$sections;')
55+
->addBody('$mode = ?;', array(123))
56+
->addBody('return self::$sections;')
5657
->addParameter('mode', new PhpLiteral('self::ORDER'));
5758

5859
$method = $class->addMethod('show')

0 commit comments

Comments
 (0)