Skip to content

Add warning for arguments in stubs that doesn't have any type info #5627

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions build/gen_stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,23 @@ public function getValue(): string {

public function getVariableName(): string {
$value = $this->getValue();
if ($value === null || strlen($value) === 0 || $value[0] !== '$') {
throw new Exception("@$this->name not followed by variable name");
if ($value === null || strlen($value) === 0) {
throw new Exception("@$this->name doesn't have any value");
}

return substr($value, 1);
$matches = [];

if ($this->name === "param") {
preg_match('/^\s*[\w\|\\\\]+\s*\$(\w+).*$/', $value, $matches);
} elseif ($this->name === "prefer-ref") {
preg_match('/^\s*\$(\w+).*$/', $value, $matches);
}

if (isset($matches[1]) === false) {
throw new Exception("@$this->name doesn't contain variable name or has an invalid format \"$value\"");
}

return $matches[1];
}
}

Expand Down Expand Up @@ -610,6 +622,7 @@ function parseFunctionLike(
$alias = null;
$isDeprecated = false;
$haveDocReturnType = false;
$docParamTypes = [];

if ($comment) {
$tags = parseDocComment($comment);
Expand All @@ -631,6 +644,8 @@ function parseFunctionLike(
$isDeprecated = true;
} else if ($tag->name === 'return') {
$haveDocReturnType = true;
} else if ($tag->name === 'param') {
$docParamTypes[$tag->getVariableName()] = true;
}
}
}
Expand All @@ -656,6 +671,10 @@ function parseFunctionLike(
}

$type = $param->type ? Type::fromNode($param->type) : null;
if ($type === null && !isset($docParamTypes[$varName])) {
throw new Exception("Missing parameter type for function $name()");
}

if ($param->default instanceof Expr\ConstFetch &&
$param->default->name->toLowerString() === "null" &&
$type && !$type->isNullable()
Expand Down Expand Up @@ -1103,7 +1122,7 @@ function initPhpParser() {
$optind = null;
$options = getopt("f", ["force-regeneration"], $optind);
$forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
$location = $argv[$optind + 1] ?? ".";
$location = $argv[$optind] ?? ".";

if (is_file($location)) {
// Generate single file.
Expand Down