Skip to content

Commit 4e608fa

Browse files
gen_stub: move funcInfoToCode() into FuncInfo
Reduce the number of global functions by moving it to instance method `FuncInfo::toArgInfoCode()`. In the process, make `FuncInfo::$numRequiredArgs` private.
1 parent 046ed23 commit 4e608fa

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

build/gen_stub.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,7 +1270,7 @@ class FuncInfo {
12701270
/** @var ArgInfo[] */
12711271
public /* readonly */ array $args;
12721272
public /* readonly */ ReturnInfo $return;
1273-
public /* readonly */ int $numRequiredArgs;
1273+
private /* readonly */ int $numRequiredArgs;
12741274
public /* readonly */ ?string $cond;
12751275
public bool $isUndocumentable;
12761276
private ?int $minimumPhpVersionIdCompatibility;
@@ -2201,6 +2201,21 @@ public function findEquivalent(array $generatedFuncInfos): ?FuncInfo {
22012201
return null;
22022202
}
22032203

2204+
public function toArgInfoCode(?int $minPHPCompatability): string {
2205+
$code = $this->return->beginArgInfo(
2206+
$this->getArgInfoName(),
2207+
$this->numRequiredArgs,
2208+
$minPHPCompatability === null || $minPHPCompatability >= PHP_81_VERSION_ID
2209+
);
2210+
2211+
foreach ($this->args as $argInfo) {
2212+
$code .= $argInfo->toZendInfo();
2213+
}
2214+
2215+
$code .= "ZEND_END_ARG_INFO()";
2216+
return $code . "\n";
2217+
}
2218+
22042219
public function __clone()
22052220
{
22062221
foreach ($this->args as $key => $argInfo) {
@@ -5047,21 +5062,6 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
50475062
return $fileInfo;
50485063
}
50495064

5050-
function funcInfoToCode(FileInfo $fileInfo, FuncInfo $funcInfo): string {
5051-
$code = $funcInfo->return->beginArgInfo(
5052-
$funcInfo->getArgInfoName(),
5053-
$funcInfo->numRequiredArgs,
5054-
$fileInfo->getMinimumPhpVersionIdCompatibility() === null || $fileInfo->getMinimumPhpVersionIdCompatibility() >= PHP_81_VERSION_ID
5055-
);
5056-
5057-
foreach ($funcInfo->args as $argInfo) {
5058-
$code .= $argInfo->toZendInfo();
5059-
}
5060-
5061-
$code .= "ZEND_END_ARG_INFO()";
5062-
return $code . "\n";
5063-
}
5064-
50655065
/**
50665066
* @template T
50675067
* @param iterable<T> $infos
@@ -5141,7 +5141,7 @@ static function (FuncInfo $funcInfo) use (&$generatedFuncInfos, $fileInfo) {
51415141
$funcInfo->getArgInfoName(), $generatedFuncInfo->getArgInfoName()
51425142
);
51435143
} else {
5144-
$code = funcInfoToCode($fileInfo, $funcInfo);
5144+
$code = $funcInfo->toArgInfoCode($fileInfo->getMinimumPhpVersionIdCompatibility());
51455145
}
51465146

51475147
$generatedFuncInfos[] = $funcInfo;

0 commit comments

Comments
 (0)