Phan\Language\Element\Clazz::hasMethodWithName PHP Method

hasMethodWithName() public method

public hasMethodWithName ( CodeBase $code_base, string $name ) : boolean
$code_base Phan\CodeBase
$name string
return boolean True if this class has a method with the given name
    public function hasMethodWithName(CodeBase $code_base, string $name) : bool
    {
        // All classes have a constructor even if it hasn't
        // been declared yet
        if ('__construct' === strtolower($name)) {
            return true;
        }
        $method_fqsen = FullyQualifiedMethodName::make($this->getFQSEN(), $name);
        return $code_base->hasMethodWithFQSEN($method_fqsen);
    }

Usage Example

Example #1
0
 /**
  * @return Method
  * A default constructor for the given class
  */
 public static function defaultConstructorForClassInContext(Clazz $clazz, Context $context, CodeBase $code_base) : Method
 {
     $method_fqsen = FullyQualifiedMethodName::make($clazz->getFQSEN(), '__construct');
     $method = new Method($context, '__construct', $clazz->getUnionType(), 0, $method_fqsen);
     if ($clazz->hasMethodWithName($code_base, $clazz->getName())) {
         $old_style_constructor = $clazz->getMethodByName($code_base, $clazz->getName());
         $method->setParameterList($old_style_constructor->getParameterList());
         $method->setNumberOfRequiredParameters($old_style_constructor->getNumberOfRequiredParameters());
         $method->setNumberOfOptionalParameters($old_style_constructor->getNumberOfOptionalParameters());
     }
     return $method;
 }