Skip to content

Commit 3137e5d

Browse files
committed
Component::tryCall() refactoring
1 parent 9c31b24 commit 3137e5d

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

src/Application/UI/Component.php

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -103,26 +103,22 @@ protected function validateParent(Nette\ComponentModel\IContainer $parent): void
103103
protected function tryCall(string $method, array $params): bool
104104
{
105105
$rc = $this->getReflection();
106-
if ($rc->hasMethod($method)) {
107-
$rm = $rc->getMethod($method);
108-
if ($rm->isPrivate()) {
109-
throw new Nette\InvalidStateException('Method ' . $rm->getName() . '() can not be called because it is private.');
110-
}
111-
112-
if (!$rm->isAbstract() && !$rm->isStatic()) {
113-
$this->checkRequirements($rm);
114-
try {
115-
$args = $rc->combineArgs($rm, $params);
116-
} catch (Nette\InvalidArgumentException $e) {
117-
throw new Nette\Application\BadRequestException($e->getMessage());
118-
}
106+
if (!$rc->hasMethod($method)) {
107+
return false;
108+
} elseif (!$rc->hasCallableMethod($method)) {
109+
throw new Nette\InvalidStateException('Method ' . Nette\Utils\Reflection::toString($rc->getMethod($method)) . ' is not callable.');
110+
}
119111

120-
$rm->invokeArgs($this, $args);
121-
return true;
122-
}
112+
$rm = $rc->getMethod($method);
113+
$this->checkRequirements($rm);
114+
try {
115+
$args = $rc->combineArgs($rm, $params);
116+
} catch (Nette\InvalidArgumentException $e) {
117+
throw new Nette\Application\BadRequestException($e->getMessage());
123118
}
124119

125-
return false;
120+
$rm->invokeArgs($this, $args);
121+
return true;
126122
}
127123

128124

0 commit comments

Comments
 (0)