Skip to content

Commit 2af71d7

Browse files
DanielEScherzerkocsismate
authored andcommitted
gen_stub: add FileInfo constructor
Move the logic from `parseStubFile()` to `FileInfo::__construct()`, and in the process inline and remove `FileInfo::setMinimumPhpVersionIdCompatibility()`.
1 parent 2df4ade commit 2af71d7

File tree

1 file changed

+32
-35
lines changed

1 file changed

+32
-35
lines changed

build/gen_stub.php

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,6 +4050,36 @@ class FileInfo {
40504050
public bool $legacyArginfoGeneration = false;
40514051
private ?int $minimumPhpVersionIdCompatibility = null;
40524052

4053+
/** @param array<int, DocCommentTag> $fileTags */
4054+
public function __construct(array $fileTags) {
4055+
foreach ($fileTags as $tag) {
4056+
if ($tag->name === 'generate-function-entries') {
4057+
$this->generateFunctionEntries = true;
4058+
$this->declarationPrefix = $tag->value ? $tag->value . " " : "";
4059+
} else if ($tag->name === 'generate-legacy-arginfo') {
4060+
if ($tag->value && !in_array((int) $tag->value, ALL_PHP_VERSION_IDS, true)) {
4061+
throw new Exception(
4062+
"Legacy PHP version must be one of: \"" . PHP_70_VERSION_ID . "\" (PHP 7.0), \"" . PHP_80_VERSION_ID . "\" (PHP 8.0), " .
4063+
"\"" . PHP_81_VERSION_ID . "\" (PHP 8.1), \"" . PHP_82_VERSION_ID . "\" (PHP 8.2), \"" . PHP_83_VERSION_ID . "\" (PHP 8.3), " .
4064+
"\"" . PHP_84_VERSION_ID . "\" (PHP 8.4), \"" . PHP_85_VERSION_ID . "\" (PHP 8.5), \"" . $tag->value . "\" provided"
4065+
);
4066+
}
4067+
4068+
$this->minimumPhpVersionIdCompatibility = ($tag->value ? (int) $tag->value : PHP_70_VERSION_ID);
4069+
} else if ($tag->name === 'generate-class-entries') {
4070+
$this->generateClassEntries = true;
4071+
$this->declarationPrefix = $tag->value ? $tag->value . " " : "";
4072+
} else if ($tag->name === 'undocumentable') {
4073+
$this->isUndocumentable = true;
4074+
}
4075+
}
4076+
4077+
// Generating class entries require generating function/method entries
4078+
if ($this->generateClassEntries && !$this->generateFunctionEntries) {
4079+
$this->generateFunctionEntries = true;
4080+
}
4081+
}
4082+
40534083
/**
40544084
* @return iterable<FuncInfo>
40554085
*/
@@ -4101,10 +4131,6 @@ public function __clone()
41014131
}
41024132
}
41034133

4104-
public function setMinimumPhpVersionIdCompatibility(?int $minimumPhpVersionIdCompatibility) {
4105-
$this->minimumPhpVersionIdCompatibility = $minimumPhpVersionIdCompatibility;
4106-
}
4107-
41084134
public function getMinimumPhpVersionIdCompatibility(): ?int {
41094135
// Non-legacy arginfo files are always PHP 8.0+ compatible
41104136
if (!$this->legacyArginfoGeneration &&
@@ -4918,37 +4944,8 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
49184944
$stmts = $parser->parse($code);
49194945
$nodeTraverser->traverse($stmts);
49204946

4921-
$fileInfo = new FileInfo;
4922-
$fileDocComments = getFileDocComments($stmts);
4923-
if ($fileDocComments !== []) {
4924-
$fileTags = parseDocComments($fileDocComments);
4925-
foreach ($fileTags as $tag) {
4926-
if ($tag->name === 'generate-function-entries') {
4927-
$fileInfo->generateFunctionEntries = true;
4928-
$fileInfo->declarationPrefix = $tag->value ? $tag->value . " " : "";
4929-
} else if ($tag->name === 'generate-legacy-arginfo') {
4930-
if ($tag->value && !in_array((int) $tag->value, ALL_PHP_VERSION_IDS, true)) {
4931-
throw new Exception(
4932-
"Legacy PHP version must be one of: \"" . PHP_70_VERSION_ID . "\" (PHP 7.0), \"" . PHP_80_VERSION_ID . "\" (PHP 8.0), " .
4933-
"\"" . PHP_81_VERSION_ID . "\" (PHP 8.1), \"" . PHP_82_VERSION_ID . "\" (PHP 8.2), \"" . PHP_83_VERSION_ID . "\" (PHP 8.3), " .
4934-
"\"" . PHP_84_VERSION_ID . "\" (PHP 8.4), \"" . PHP_85_VERSION_ID . "\" (PHP 8.5), \"" . $tag->value . "\" provided"
4935-
);
4936-
}
4937-
4938-
$fileInfo->setMinimumPhpVersionIdCompatibility($tag->value ? (int) $tag->value : PHP_70_VERSION_ID);
4939-
} else if ($tag->name === 'generate-class-entries') {
4940-
$fileInfo->generateClassEntries = true;
4941-
$fileInfo->declarationPrefix = $tag->value ? $tag->value . " " : "";
4942-
} else if ($tag->name === 'undocumentable') {
4943-
$fileInfo->isUndocumentable = true;
4944-
}
4945-
}
4946-
}
4947-
4948-
// Generating class entries require generating function/method entries
4949-
if ($fileInfo->generateClassEntries && !$fileInfo->generateFunctionEntries) {
4950-
$fileInfo->generateFunctionEntries = true;
4951-
}
4947+
$fileTags = parseDocComments(getFileDocComments($stmts));
4948+
$fileInfo = new FileInfo($fileTags);
49524949

49534950
handleStatements($fileInfo, $stmts, $prettyPrinter);
49544951
return $fileInfo;

0 commit comments

Comments
 (0)