mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
gen_stub: move parseStubFile()
into FileInfo
Reduce the number of global functions by moving it to static method `FileInfo::parseStubFile()`. Additionally, make `FileInfo::handleStatements()` private now that the only caller is part of the class.
This commit is contained in:
parent
05dbf0707a
commit
2b0cb760d4
1 changed files with 22 additions and 22 deletions
|
@ -95,7 +95,7 @@ function processStubFile(string $stubFile, Context $context, bool $includeOnly =
|
|||
if (!$fileInfo = $context->parsedFiles[$stubFile] ?? null) {
|
||||
initPhpParser();
|
||||
$stubContent = $stubCode ?? file_get_contents($stubFile);
|
||||
$fileInfo = parseStubFile($stubContent);
|
||||
$fileInfo = FileInfo::parseStubFile($stubContent);
|
||||
$context->parsedFiles[$stubFile] = $fileInfo;
|
||||
|
||||
foreach ($fileInfo->dependencies as $dependency) {
|
||||
|
@ -4295,7 +4295,27 @@ class FileInfo {
|
|||
return $legacyFileInfo;
|
||||
}
|
||||
|
||||
public function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrinter): void {
|
||||
public static function parseStubFile(string $code): FileInfo {
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative());
|
||||
$nodeTraverser = new PhpParser\NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
|
||||
$prettyPrinter = new class extends Standard {
|
||||
protected function pName_FullyQualified(Name\FullyQualified $node): string {
|
||||
return implode('\\', $node->getParts());
|
||||
}
|
||||
};
|
||||
|
||||
$stmts = $parser->parse($code);
|
||||
$nodeTraverser->traverse($stmts);
|
||||
|
||||
$fileTags = DocCommentTag::parseDocComments(getFileDocComments($stmts));
|
||||
$fileInfo = new FileInfo($fileTags);
|
||||
|
||||
$fileInfo->handleStatements($stmts, $prettyPrinter);
|
||||
return $fileInfo;
|
||||
}
|
||||
|
||||
private function handleStatements(array $stmts, PrettyPrinterAbstract $prettyPrinter): void {
|
||||
$conds = [];
|
||||
foreach ($stmts as $stmt) {
|
||||
$cond = self::handlePreprocessorConditions($conds, $stmt);
|
||||
|
@ -5031,26 +5051,6 @@ function getFileDocComments(array $stmts): array {
|
|||
);
|
||||
}
|
||||
|
||||
function parseStubFile(string $code): FileInfo {
|
||||
$parser = new PhpParser\Parser\Php7(new PhpParser\Lexer\Emulative());
|
||||
$nodeTraverser = new PhpParser\NodeTraverser;
|
||||
$nodeTraverser->addVisitor(new PhpParser\NodeVisitor\NameResolver);
|
||||
$prettyPrinter = new class extends Standard {
|
||||
protected function pName_FullyQualified(Name\FullyQualified $node): string {
|
||||
return implode('\\', $node->getParts());
|
||||
}
|
||||
};
|
||||
|
||||
$stmts = $parser->parse($code);
|
||||
$nodeTraverser->traverse($stmts);
|
||||
|
||||
$fileTags = DocCommentTag::parseDocComments(getFileDocComments($stmts));
|
||||
$fileInfo = new FileInfo($fileTags);
|
||||
|
||||
$fileInfo->handleStatements($stmts, $prettyPrinter);
|
||||
return $fileInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @param iterable<T> $infos
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue