/** * @return Method * The method with the given name */ public function getMethodByNameInContext(CodeBase $code_base, string $name, Context $context) : Method { $method_fqsen = FullyQualifiedMethodName::make($this->getFQSEN(), $name); if (!$code_base->hasMethod($method_fqsen)) { if ('__construct' === $name) { // Create a default constructor if its requested // but doesn't exist yet $default_constructor = Method::defaultConstructorForClassInContext($this, $context->withClassFQSEN($this->getFQSEN())); $this->addMethod($code_base, $default_constructor); return $default_constructor; } throw new CodeBaseException($method_fqsen, "Method with name {$name} does not exist for class {$this->getFQSEN()}."); } return $code_base->getMethod($method_fqsen); }