Skip to content

Commit 7a69c5c

Browse files
committed
Add warning for missing argument types in stubs
1 parent d8dfb21 commit 7a69c5c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

build/gen_stub.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,8 +576,19 @@ public function getValue(): string {
576576

577577
public function getVariableName(): string {
578578
$value = $this->getValue();
579-
if ($value === null || strlen($value) === 0 || $value[0] !== '$') {
580-
throw new Exception("@$this->name not followed by variable name");
579+
if ($value === null || strlen($value) === 0) {
580+
throw new Exception("@$this->name doesn't have any value");
581+
}
582+
583+
if ($this->name === "param") {
584+
$pos = strpos($value, " ");
585+
if ($pos !== false) {
586+
$value = substr($value, $pos + 1);
587+
}
588+
}
589+
590+
if ($value[0] !== '$') {
591+
throw new Exception("@$this->name doesn't contain variable name");
581592
}
582593

583594
return substr($value, 1);
@@ -610,6 +621,7 @@ function parseFunctionLike(
610621
$alias = null;
611622
$isDeprecated = false;
612623
$haveDocReturnType = false;
624+
$docParamTypes = [];
613625

614626
if ($comment) {
615627
$tags = parseDocComment($comment);
@@ -631,13 +643,16 @@ function parseFunctionLike(
631643
$isDeprecated = true;
632644
} else if ($tag->name === 'return') {
633645
$haveDocReturnType = true;
646+
} else if ($tag->name === 'param') {
647+
$docParamTypes[$tag->getVariableName()] = true;
634648
}
635649
}
636650
}
637651

638652
$args = [];
639653
$numRequiredArgs = 0;
640654
$foundVariadic = false;
655+
$hasParameterWarning = false;
641656
foreach ($func->getParams() as $i => $param) {
642657
$varName = $param->var->name;
643658
$preferRef = !empty($paramMeta[$varName]['preferRef']);
@@ -656,6 +671,12 @@ function parseFunctionLike(
656671
}
657672

658673
$type = $param->type ? Type::fromNode($param->type) : null;
674+
if ($type === null && !isset($docParamTypes[$varName]) && !$hasParameterWarning) {
675+
$hasParameterWarning = true;
676+
//throw new Exception("Missing argument type for function $name()");
677+
echo "Warning: Missing argument type for function $name()\n";
678+
}
679+
659680
if ($param->default instanceof Expr\ConstFetch &&
660681
$param->default->name->toLowerString() === "null" &&
661682
$type && !$type->isNullable()

0 commit comments

Comments
 (0)