tolerant-php-parser/tools/PrintApiDocumentation.php

65 строки
2.6 KiB
PHP
Исходник Постоянная ссылка Обычный вид История

<?php
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
2017-01-30 02:06:13 +03:00
use Microsoft\PhpParser\Node\MethodDeclaration;
use Microsoft\PhpParser\Node\Statement\ClassDeclaration;
use Microsoft\PhpParser\Parser;
require_once __DIR__ . "/../src/bootstrap.php";
$files = [
__DIR__ . "/../src/Node.php",
__DIR__ . "/../src/Token.php",
__DIR__ . "/../src/Parser.php",
__DIR__ . "/../src/DiagnosticsProvider.php",
__DIR__ . "/../src/PositionUtilities.php",
2017-02-02 04:26:45 +03:00
__DIR__ . "/../src/LineCharacterPosition.php",
__DIR__ . "/../src/MissingToken.php",
__DIR__ . "/../src/SkippedToken.php"
];
$parser = new Parser();
echo "# API Documentation" . PHP_EOL;
echo "> Note: This documentation was auto-generated using this parser to help dogfood the API. It may be incomplete. Please contribute fixes to
`tools/PrintApiDocumentation.php` and suggest API improvements.\n<hr>\n\n";
foreach ($files as $file) {
$ast = $parser->parseSourceFile(file_get_contents($file));
2020-08-10 17:20:57 +03:00
foreach ($ast->getDescendantNodes() as $descendant) {
if ($descendant instanceof ClassDeclaration) {
$className = $descendant->name->getText($descendant->getFileContents());
echo "## " . $className . PHP_EOL;
// TODO consider not having a separate classMemberDeclarations node
foreach ($descendant->classMembers->classMemberDeclarations as $member) {
2020-08-10 17:20:57 +03:00
// TODO: Maybe ask a class directly for all its method declarations
if ($member instanceof MethodDeclaration) {
2020-08-10 17:20:57 +03:00
if (!$member->isPublic()) {
continue;
}
2020-08-10 17:20:57 +03:00
$signature = $member->getSignatureFormatted();
$description = $member->getDescriptionFormatted();
if (strlen($description) <= 0) {
$description = "> TODO: add doc comment\n";
}
2020-08-10 17:20:57 +03:00
echo "### " . $className . "::" . $member->getName() . PHP_EOL;
echo $description . PHP_EOL;
echo "```php\n$signature\n```" . PHP_EOL;
}
}
}
}
}
echo "## Node types
> TODO: complete documentation - in addition to the helper methods on the Node base class,
every Node object has properties specific to the Node type. Browse `src/Node/` to explore these properties.";