BetterReflection\Reflection\ReflectionClass::getMethod PHP Method

getMethod() public method

Get a single method with the name $methodName.
public getMethod ( string $methodName ) : BetterReflection\Reflection\ReflectionMethod
$methodName string
return BetterReflection\Reflection\ReflectionMethod
    public function getMethod($methodName)
    {
        $methods = $this->getMethodsIndexedByName();
        if (!isset($methods[$methodName])) {
            throw new \OutOfBoundsException('Could not find method: ' . $methodName);
        }
        return $methods[$methodName];
    }

Usage Example

 public function testFetchingFqsenThrowsExceptionWithNonObjectName()
 {
     $sourceLocator = new StringSourceLocator('<?php class Foo {}');
     $reflector = new ClassReflector($sourceLocator);
     $identifier = new Identifier('Foo', new IdentifierType(IdentifierType::IDENTIFIER_CLASS));
     $locatedSource = $sourceLocator->__invoke($identifier);
     $node = new Class_('Foo');
     $reflection = ReflectionClass::createFromNode($reflector, $node, $locatedSource);
     $reflectionClassReflection = new \ReflectionClass(ReflectionClass::class);
     $reflectionClassMethodReflection = $reflectionClassReflection->getMethod('getFqsenFromNamedNode');
     $reflectionClassMethodReflection->setAccessible(true);
     $nameNode = new Name(['int']);
     $this->setExpectedException(\Exception::class, 'Unable to determine FQSEN for named node');
     $reflectionClassMethodReflection->invoke($reflection, $nameNode);
 }
All Usage Examples Of BetterReflection\Reflection\ReflectionClass::getMethod