PHPStan\Reflection\ClassReflection::hasMethod PHP Method

hasMethod() public method

public hasMethod ( string $methodName ) : boolean
$methodName string
return boolean
    public function hasMethod(string $methodName) : bool
    {
        foreach ($this->methodsClassReflectionExtensions as $extension) {
            if ($extension->hasMethod($this, $methodName)) {
                return true;
            }
        }
        return false;
    }

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);
 }