Skip to content

Commit 43c9b67

Browse files
committed
FunctionLike: added getParameter() & hasParameter()
1 parent d34e60d commit 43c9b67

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/PhpGenerator/Traits/FunctionLike.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ public function getParameters(): array
8585
}
8686

8787

88+
public function getParameter(string $name): Parameter
89+
{
90+
return $this->parameters[$name] ?? throw new Nette\InvalidArgumentException("Parameter '$name' not found.");
91+
}
92+
93+
8894
/**
8995
* @param string $name without $
9096
*/
@@ -109,6 +115,12 @@ public function removeParameter(string $name): static
109115
}
110116

111117

118+
public function hasParameter(string $name): bool
119+
{
120+
return isset($this->parameters[$name]);
121+
}
122+
123+
112124
public function setVariadic(bool $state = true): static
113125
{
114126
$this->variadic = $state;

tests/PhpGenerator/ClassType.phpt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,11 @@ Assert::false($m->isPublic());
124124
$method = $class->addMethod('show')
125125
->setAbstract();
126126

127-
$method->addParameter('foo');
127+
$p = $method->addParameter('foo');
128+
Assert::true($method->hasParameter('foo'));
129+
Assert::same($p, $method->getParameter('foo'));
128130
$method->removeParameter('foo');
131+
Assert::false($method->hasParameter('foo'));
129132

130133
$method->addParameter('item');
131134

0 commit comments

Comments
 (0)