Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions extractor/extract.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ public function clear(): void
continue;
}
$functions[strtolower($namespacedName)] = $pathPart;
$stmt = $this->filterFunctionPhpDocs($stmt);
} else {
throw new \Exception(sprintf('Unhandled node type %s in %s on line %s.', get_class($stmt), $stubPath, $stmt->getLine()));
}
Expand Down Expand Up @@ -820,6 +821,49 @@ private function filterClassPhpDocs(Node\Stmt\ClassLike $class): Node\Stmt\Class
return $class;
}

private function filterFunctionPhpDocs(Node\Stmt\Function_ $function): Node\Stmt\Function_
{
$namespacedName = $function->namespacedName->toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment with a link to a related discussion why precisely these functions need to be fixed would be appreciated!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the comment inside the if condition if it's ok.

if (in_array($namespacedName, [
'xml_set_element_handler',
'xml_set_character_data_handler',
'xml_set_processing_instruction_handler',
'xml_set_default_handler',
'xml_set_unparsed_entity_decl_handler',
'xml_set_notation_decl_handler',
'xml_set_external_entity_ref_handler',
'xml_set_start_namespace_decl_handler',
'xml_set_end_namespace_decl_handler',
], true)) {
/**
* Stub was updated in PHP 8.4, but the support for `callable|string|null` already exists before.
*
* @see https://github.com/php/php-src/pull/12340/files#diff-2c2d210a6a8bc8eae404fa6938be724484865b47cc574d94d24e2c18524c1b40
*/
$comments = $function->getAttribute('comments');
if (null !== $comments) {
$function->setAttribute('comments', array_map(
fn (Comment\Doc $doc): Comment\Doc => new Comment\Doc(
str_replace(
'@param callable $',
'@param callable|string|null $',
$doc->getText(),
),
$doc->getStartLine(),
$doc->getStartFilePos(),
$doc->getStartTokenPos(),
$doc->getEndLine(),
$doc->getEndFilePos(),
$doc->getEndTokenPos(),
),
$comments
));
}
}

return $function;
}

private function parseDocComment(string $docComment): PhpDocNode
{
$tokens = new TokenIterator($this->phpDocLexer->tokenize($docComment));
Expand Down