Skip to content

Commit 75ecc9c

Browse files
committed
Method & Property: setVisibility() checks argument
1 parent 24ccd2a commit 75ecc9c

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/PhpGenerator/ClassType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ public function addMethod($name)
515515
{
516516
$method = new Method;
517517
if ($this->type === 'interface') {
518-
$method->setVisibility('')->setBody(FALSE);
518+
$method->setVisibility(NULL)->setBody(FALSE);
519519
} else {
520520
$method->setVisibility('public');
521521
}

src/PhpGenerator/Method.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Method extends Nette\Object
3232
/** @var bool */
3333
private $static = FALSE;
3434

35-
/** @var string public|protected|private or none */
35+
/** @var string|NULL public|protected|private */
3636
private $visibility;
3737

3838
/** @var bool */
@@ -252,11 +252,14 @@ public function isStatic()
252252

253253

254254
/**
255-
* @param string public|protected|private
255+
* @param string|NULL public|protected|private
256256
* @return self
257257
*/
258258
public function setVisibility($val)
259259
{
260+
if (!in_array($val, array('public', 'protected', 'private', NULL), TRUE)) {
261+
throw new Nette\InvalidArgumentException('Argument must be public|protected|private|NULL.');
262+
}
260263
$this->visibility = (string) $val;
261264
return $this;
262265
}

src/PhpGenerator/Property.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,9 @@ public function isStatic()
114114
*/
115115
public function setVisibility($val)
116116
{
117+
if (!in_array($val, array('public', 'protected', 'private'), TRUE)) {
118+
throw new Nette\InvalidArgumentException('Argument must be public|protected|private.');
119+
}
117120
$this->visibility = (string) $val;
118121
return $this;
119122
}

0 commit comments

Comments
 (0)