public function visitMethod(Decl $node) : Context
{
assert($this->context->isInFunctionLikeScope(), "Must be in function-like scope to get method");
$method = $this->context->getFunctionLikeInScope($this->code_base);
$return_type = $method->getUnionType();
assert($method instanceof Method, "Function found where method expected");
$has_interface_class = false;
if ($method instanceof Method) {
try {
$class = $method->getClass($this->code_base);
$has_interface_class = $class->isInterface();
} catch (\Exception $exception) {
}
}
if ($method instanceof Method) {
if (!$method->isAbstract() && !$has_interface_class && !$return_type->isEmpty() && !$method->getHasReturn() && !$this->declOnlyThrows($node) && !$return_type->hasType(VoidType::instance()) && !$return_type->hasType(NullType::instance())) {
$this->emitIssue(Issue::TypeMissingReturn, $node->lineno ?? 0, (string) $method->getFQSEN(), (string) $return_type);
}
if ($method->isStatic() && $method->getUnionType()->hasTemplateType()) {
$this->emitIssue(Issue::TemplateTypeStaticMethod, $node->lineno ?? 0, (string) $method->getFQSEN());
}
}
if ($method instanceof Func) {
if (!$return_type->isEmpty() && !$method->getHasReturn() && !$this->declOnlyThrows($node) && !$return_type->hasType(VoidType::instance()) && !$return_type->hasType(NullType::instance())) {
$this->emitIssue(Issue::TypeMissingReturn, $node->lineno ?? 0, (string) $method->getFQSEN(), (string) $return_type);
}
}
$parameters_seen = [];
foreach ($method->getParameterList() as $i => $parameter) {
if (isset($parameters_seen[$parameter->getName()])) {
$this->emitIssue(Issue::ParamRedefined, $node->lineno ?? 0, '$' . $parameter->getName());
} else {
$parameters_seen[$parameter->getName()] = $i;
}
}
return $this->context;
}