-
Notifications
You must be signed in to change notification settings - Fork 1
/
generator.php
55 lines (45 loc) · 1.47 KB
/
generator.php
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
48
49
50
51
52
53
54
55
<?php
declare(strict_types=1);
$folder = './stubs';
$destination = dirname(__DIR__, 2) . '/src/stubs.php';
$phpFiles = new RegexIterator(
new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($folder)
),
'/.*\.php$/',
RegexIterator::GET_MATCH
);
$removeAttributesList = implode('|', [
'LanguageLevelTypeAware',
'LanguageAware',
'ElementAvailable',
'PhpStormStubsElementAvailable',
'PhpVersionAware',
'TypeContract',
'ExpectedValues',
'\\\\SensitiveParameter',
]);
$stubs = [];
foreach ($phpFiles as $file) {
$path = $file[0];
$contents = file_get_contents($path);
if (!preg_match_all('/^function (\w+)\(.*\)/m', $contents, $matches, PREG_SET_ORDER)) {
continue;
}
foreach ($matches as $match) {
$functionLine = preg_replace('/#\[(?:' . $removeAttributesList . ')(?:\(.+\)|)] /', '', $match[0]);
//$functionLine = 'function headers_sent(string &$filename, int &$line): bool';
preg_match_all('/(\$\w+)/', $functionLine, $arguments,);
preg_match('/\((.+)\)/', $functionLine, $signatureArguments);
$stubs[$match[1]] = [
'signatureArguments' => $signatureArguments[1] ?? '',
'arguments' => implode(', ', $arguments[0] ?? []),
];
}
}
$patches = require './patches.php';
$result = array_merge($stubs, $patches);
file_put_contents(
$destination,
'<?php' . PHP_EOL . PHP_EOL . 'return ' . var_export($result, true) . ';'
);