generated from ghostwriter/wip
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.php
More file actions
47 lines (36 loc) · 1.4 KB
/
generate.php
File metadata and controls
47 lines (36 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
use Ghostwriter\GitHubCli\Interface\GitHubCliInterface;
require \implode(\DIRECTORY_SEPARATOR, [\dirname(__DIR__), 'vendor', 'autoload.php']);
$workspace = __DIR__;
$lines = [
'# GitHub Cli Documentation',
'',
'```php',
'use Ghostwriter\GitHubCli\GitHubCli;',
'',
'$gh = GitHubCli::new();',
];
$class = GitHubCliInterface::class;
$reflectionClass = new \ReflectionClass($class);
$methods = $reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if ($method->isConstructor() || $method->isDestructor() || $method->isStatic()) {
continue;
}
$docComment = $method->getDocComment();
if (false === $docComment) {
throw new \RuntimeException('No doc comment found for method: ' . $method->getName());
}
// Clean up the doc comment for better readability
$cleanedDocComment = \preg_replace('/^\s*\/\*\*|\s*\*\/\s*$/', '', $docComment);
$cleanedDocComment = \preg_replace('/^\s*\*\s?/m', '', $cleanedDocComment);
$methodName = $method->getName();
$lines[] = '';
$lines[] = '// ' . \mb_trim($cleanedDocComment);
$lines[] = '$gh->' . $methodName . '(\'--help\');';
}
$lines[] = '```';
$documentation = \implode(\PHP_EOL, $lines);
\file_put_contents($workspace . \DIRECTORY_SEPARATOR . 'README.md', $documentation);
echo 'Documentation generated successfully.' . \PHP_EOL;