Skip to content

Commit

Permalink
Fix #5: Use fromCallable in ListenerCollection::getParameterType() (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Sep 8, 2020
1 parent 73f7634 commit c931445
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/Provider/ListenerCollection.php
Expand Up @@ -68,27 +68,8 @@ private function getParameterType(callable $callable): string
{
// This try-catch is only here to keep OCD linters happy about uncaught reflection exceptions.
try {
switch (true) {
// See note on isClassCallable() for why this must be the first case.
case $this->isClassCallable($callable):
$reflect = new \ReflectionClass($callable[0]);
$params = $reflect->getMethod($callable[1])->getParameters();
break;
case $this->isFunctionCallable($callable):
case $this->isClosureCallable($callable):
$reflect = new \ReflectionFunction($callable);
$params = $reflect->getParameters();
break;
case $this->isObjectCallable($callable):
$reflect = new \ReflectionObject($callable[0]);
$params = $reflect->getMethod($callable[1])->getParameters();
break;
case $this->isInvokable($callable):
$params = (new \ReflectionMethod($callable, '__invoke'))->getParameters();
break;
default:
throw new \InvalidArgumentException('Not a recognized type of callable');
}
$closure = new \ReflectionFunction(\Closure::fromCallable($callable));
$params = $closure->getParameters();

$reflectedType = isset($params[0]) ? $params[0]->getType() : null;
if ($reflectedType === null) {
Expand Down

0 comments on commit c931445

Please sign in to comment.