-
-
Notifications
You must be signed in to change notification settings - Fork 592
Expand file tree
/
Copy pathgenerate-phpstorm-meta-file.php
More file actions
28 lines (21 loc) · 974 Bytes
/
generate-phpstorm-meta-file.php
File metadata and controls
28 lines (21 loc) · 974 Bytes
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
<?php
use PHPStan\PhpDocParser\Lexer\Lexer;
use PHPStan\PhpDocParser\Parser\ConstExprParser;
use PHPStan\PhpDocParser\Parser\PhpDocParser;
use PHPStan\PhpDocParser\Parser\TokenIterator;
use PHPStan\PhpDocParser\Parser\TypeParser;
require 'vendor/autoload.php';
$reflection = new ReflectionClass(\Github\Client::class);
$lexer = new Lexer();
$constExprParser = new ConstExprParser();
$typeParser = new TypeParser($constExprParser);
$phpDocParser = new PhpDocParser($typeParser, $constExprParser);
$tokens = new TokenIterator($lexer->tokenize($reflection->getDocComment()));
$phpDocNode = $phpDocParser->parse($tokens);
$replacements = '';
foreach ($phpDocNode->getTagsByName('@method') as $node) {
$replacements .= "\"{$node->value->methodName}\" => \Github\\{$node->value->returnType->name}::class,".PHP_EOL;
}
$str = file_get_contents('./.phpstorm.meta.stub');
$str = str_replace('$METHODS$', $replacements, $str);
file_put_contents('.phpstorm.meta.php', $str);