PHPStan\Reflection\ClassReflection::getMethod PHP Method

getMethod() public method

public getMethod ( string $methodName ) : MethodReflection
$methodName string
return MethodReflection
    public function getMethod(string $methodName) : MethodReflection
    {
        if (!isset($this->methods[$methodName])) {
            foreach ($this->methodsClassReflectionExtensions as $extension) {
                if ($extension->hasMethod($this, $methodName)) {
                    return $this->methods[$methodName] = $extension->getMethod($this, $methodName);
                }
            }
        }
        if (!isset($this->methods[$methodName])) {
            throw new \PHPStan\Reflection\MissingMethodFromReflectionException($this->getName(), $methodName);
        }
        return $this->methods[$methodName];
    }

Usage Example

 /**
  * @param \PHPStan\Reflection\ClassReflection $classReflection
  * @param string $propertyName
  * @return \PHPStan\Reflection\MethodReflection|null
  */
 private function getMethodByProperty(ClassReflection $classReflection, string $propertyName)
 {
     $getterMethodName = sprintf('get%s', ucfirst($propertyName));
     if (!$classReflection->hasMethod($getterMethodName)) {
         return null;
     }
     return $classReflection->getMethod($getterMethodName);
 }