Skip to content

Commit 74e9af6

Browse files
committed
fixup! Add warning for missing argument types in stubs
1 parent d53d10a commit 74e9af6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

build/gen_stub.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -580,18 +580,19 @@ public function getVariableName(): string {
580580
throw new Exception("@$this->name doesn't have any value");
581581
}
582582

583+
$matches = [];
584+
583585
if ($this->name === "param") {
584-
$pos = strpos($value, " ");
585-
if ($pos !== false) {
586-
$value = substr($value, $pos + 1);
587-
}
586+
preg_match('/^\s*[\w\|\\\]+\s*\$(\w+).*$/', $value, $matches);
587+
} elseif ($this->name === "prefer-ref") {
588+
preg_match('/^\s*\$(\w+).*$/', $value, $matches);
588589
}
589590

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

594-
return substr($value, 1);
595+
return $matches[1];
595596
}
596597
}
597598

@@ -673,8 +674,8 @@ function parseFunctionLike(
673674
$type = $param->type ? Type::fromNode($param->type) : null;
674675
if ($type === null && !isset($docParamTypes[$varName]) && !$hasParameterWarning) {
675676
$hasParameterWarning = true;
676-
//throw new Exception("Missing argument type for function $name()");
677-
echo "Warning: Missing argument type for function $name()\n";
677+
//throw new Exception("Missing parameter type for function $name()");
678+
echo "Warning: Missing parameter type for function $name()\n";
678679
}
679680

680681
if ($param->default instanceof Expr\ConstFetch &&
@@ -1124,7 +1125,7 @@ function initPhpParser() {
11241125
$optind = null;
11251126
$options = getopt("f", ["force-regeneration"], $optind);
11261127
$forceRegeneration = isset($options["f"]) || isset($options["force-regeneration"]);
1127-
$location = $argv[$optind + 1] ?? ".";
1128+
$location = $argv[$optind] ?? ".";
11281129

11291130
if (is_file($location)) {
11301131
// Generate single file.

0 commit comments

Comments
 (0)