|
5 | 5 | *--------------------------------------------------------------------------------------------*/ |
6 | 6 |
|
7 | 7 | use Microsoft\PhpParser\Node\MethodDeclaration; |
8 | | -use Microsoft\PhpParser\Node\PropertyDeclaration; |
9 | 8 | use Microsoft\PhpParser\Node\Statement\ClassDeclaration; |
10 | 9 | use Microsoft\PhpParser\Parser; |
11 | | -use Microsoft\PhpParser\Token; |
12 | | -use Microsoft\PhpParser\TokenKind; |
13 | 10 |
|
14 | 11 | require_once __DIR__ . "/../src/bootstrap.php"; |
15 | 12 |
|
|
32 | 29 |
|
33 | 30 | foreach ($files as $file) { |
34 | 31 | $ast = $parser->parseSourceFile(file_get_contents($file)); |
| 32 | + |
35 | 33 | foreach ($ast->getDescendantNodes() as $descendant) { |
36 | 34 | if ($descendant instanceof ClassDeclaration) { |
37 | 35 | $className = $descendant->name->getText($descendant->getFileContents()); |
38 | 36 | echo "## " . $className . PHP_EOL; |
39 | 37 |
|
40 | 38 | // TODO consider not having a separate classMemberDeclarations node |
41 | 39 | foreach ($descendant->classMembers->classMemberDeclarations as $member) { |
| 40 | + // TODO: Maybe ask a class directly for all its method declarations |
42 | 41 | if ($member instanceof MethodDeclaration) { |
43 | | - // TODO this should be a helper function on any modified types |
44 | | - foreach ($member->modifiers as $modifier) { |
45 | | - if ($modifier->kind === TokenKind::PublicKeyword) { |
46 | | - $fileContents = $member->getFileContents(); |
47 | | - $signature = implode(" ", getSignatureParts($member)); |
48 | | - $comment = trim($member->getLeadingCommentAndWhitespaceText(), "\r\n"); |
| 42 | + if (!$member->isPublic()) { |
| 43 | + continue; |
| 44 | + } |
49 | 45 |
|
50 | | - $commentParts = explode("\n", $comment); |
51 | | - $description = []; |
52 | | - foreach ($commentParts as $i=>$part) { |
53 | | - $part = trim($part, "*\r\t /"); |
54 | | - if (isset($part[0])) { |
55 | | - if ($part[0] === "@") { |
56 | | - break; |
57 | | - } |
58 | | - $description[] = $part; |
59 | | - } |
60 | | - } |
61 | | - $comment = implode(" ", $description); |
62 | | - if (strlen(trim($comment, " \t")) === 0) { |
63 | | - $comment = "> TODO: add doc comment\n"; |
64 | | - } |
65 | | - echo "### " . $className . "::" . $member->name->getText($member->getFileContents()) . PHP_EOL; |
66 | | - echo $comment . PHP_EOL; |
67 | | - echo "```php\n$signature\n```" . PHP_EOL; |
68 | | - } |
| 46 | + $signature = $member->getSignatureFormatted(); |
| 47 | + |
| 48 | + $description = $member->getDescriptionFormatted(); |
| 49 | + if (strlen($description) <= 0) { |
| 50 | + $description = "> TODO: add doc comment\n"; |
69 | 51 | } |
| 52 | + |
| 53 | + echo "### " . $className . "::" . $member->getName() . PHP_EOL; |
| 54 | + echo $description . PHP_EOL; |
| 55 | + echo "```php\n$signature\n```" . PHP_EOL; |
70 | 56 | } |
71 | 57 | } |
72 | 58 | } |
|
76 | 62 | echo "## Node types |
77 | 63 | > TODO: complete documentation - in addition to the helper methods on the Node base class, |
78 | 64 | every Node object has properties specific to the Node type. Browse `src/Node/` to explore these properties."; |
79 | | - |
80 | | -function getSignatureParts(MethodDeclaration $methodDeclaration) : array { |
81 | | - // TODO - something like this in API? |
82 | | - $parts = []; |
83 | | - foreach ($methodDeclaration->getChildNodesAndTokens() as $i=>$child) { |
84 | | - if ($i === "compoundStatementOrSemicolon") { |
85 | | - return $parts; |
86 | | - } |
87 | | - $parts[] = $child instanceof Token |
88 | | - ? $child->getText($methodDeclaration->getFileContents()) |
89 | | - : $child->getText(); |
90 | | - }; |
91 | | - return $parts; |
92 | | -} |
0 commit comments