Skip to content

Commit

Permalink
FunctionLike: added getParameter() & hasParameter()
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jul 30, 2023
1 parent d34e60d commit 43c9b67
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions src/PhpGenerator/Traits/FunctionLike.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ public function getParameters(): array
}


public function getParameter(string $name): Parameter
{
return $this->parameters[$name] ?? throw new Nette\InvalidArgumentException("Parameter '$name' not found.");
}


/**
* @param string $name without $
*/
Expand All @@ -109,6 +115,12 @@ public function removeParameter(string $name): static
}


public function hasParameter(string $name): bool
{
return isset($this->parameters[$name]);
}


public function setVariadic(bool $state = true): static
{
$this->variadic = $state;
Expand Down
5 changes: 4 additions & 1 deletion tests/PhpGenerator/ClassType.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ Assert::false($m->isPublic());
$method = $class->addMethod('show')
->setAbstract();

$method->addParameter('foo');
$p = $method->addParameter('foo');
Assert::true($method->hasParameter('foo'));
Assert::same($p, $method->getParameter('foo'));
$method->removeParameter('foo');
Assert::false($method->hasParameter('foo'));

$method->addParameter('item');

Expand Down

0 comments on commit 43c9b67

Please sign in to comment.