Skip to content

Commit ca0ca86

Browse files
committed
Method: none body represents NULL instead of FALSE (BC break)
1 parent 901d3bf commit ca0ca86

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ public function addMethod($name)
493493
{
494494
$method = (new Method($name))->setNamespace($this->namespace);
495495
if ($this->type === 'interface') {
496-
$method->setBody(FALSE);
496+
$method->setBody(NULL);
497497
} else {
498498
$method->setVisibility('public');
499499
}

src/PhpGenerator/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function fromMethodReflection(\ReflectionMethod $from)
6565
$method->setVisibility($from->isPrivate() ? 'private' : ($from->isProtected() ? 'protected' : ($isInterface ? NULL : 'public')));
6666
$method->setFinal($from->isFinal());
6767
$method->setAbstract($from->isAbstract() && !$isInterface);
68-
$method->setBody($from->isAbstract() ? FALSE : '');
68+
$method->setBody($from->isAbstract() ? NULL : '');
6969
$method->setReturnReference($from->returnsReference());
7070
$method->setVariadic($from->isVariadic());
7171
$method->setComment(Helpers::unformatDocComment((string) $from->getDocComment()));

src/PhpGenerator/Method.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
/**
1616
* Class method.
1717
*
18-
* @property string|FALSE $body
18+
* @property string|NULL $body
1919
*/
2020
class Method
2121
{
@@ -25,6 +25,9 @@ class Method
2525
use Traits\VisibilityAware;
2626
use Traits\CommentAware;
2727

28+
/** @var string|NULL */
29+
private $body = '';
30+
2831
/** @var bool */
2932
private $static = FALSE;
3033

@@ -77,25 +80,29 @@ public function __toString()
7780
. $this->name
7881
. $this->parametersToString()
7982
. $this->returnTypeToString()
80-
. ($this->abstract || $this->body === FALSE
83+
. ($this->abstract || $this->body === NULL
8184
? ';'
8285
: "\n{\n" . Nette\Utils\Strings::indent(ltrim(rtrim($this->body) . "\n"), 1) . '}');
8386
}
8487

8588

8689
/**
87-
* @param string|FALSE
90+
* @param string|NULL
8891
* @return static
8992
*/
9093
public function setBody($code, array $args = NULL)
9194
{
95+
if ($code === FALSE) {
96+
$code = NULL;
97+
trigger_error(__METHOD__ . '() use NULL instead of FALSE', E_USER_DEPRECATED);
98+
}
9299
$this->body = $args === NULL ? $code : Helpers::formatArgs($code, $args);
93100
return $this;
94101
}
95102

96103

97104
/**
98-
* @return string|FALSE
105+
* @return string|NULL
99106
*/
100107
public function getBody()
101108
{

0 commit comments

Comments
 (0)