Skip to content

Commit 6b9f365

Browse files
committed
Refactor
1 parent 8cfb3c1 commit 6b9f365

4 files changed

+62
-10
lines changed

bin/gen_base_callmap.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function paramsToEntries(ReflectionFunctionAbstract $reflectionFunction): array
6262

6363
$args = paramsToEntries($func);
6464

65-
$callmap[$name] = $args;
65+
$callmap[strtolower($name)] = $args;
6666
}
6767

6868
foreach (get_declared_classes() as $class) {
@@ -74,7 +74,7 @@ function paramsToEntries(ReflectionFunctionAbstract $reflectionFunction): array
7474
foreach ($refl->getMethods() as $method) {
7575
$args = paramsToEntries($method);
7676

77-
$callmap[$class.'::'.$method->getName()] = $args;
77+
$callmap[strtolower($class.'::'.$method->getName())] = $args;
7878
}
7979
}
8080

bin/gen_callmap.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
declare(strict_types=1);
44

5-
// Written by SamMousa in https://github.com/vimeo/psalm/issues/8101, finalized by @danog
6-
75
require __DIR__ . '/gen_callmap_utils.php';
86

7+
$callMap = require "dictionaries/CallMap.php";
8+
$orig = $callMap;
9+
910
foreach ($callMap as $functionName => &$entry) {
1011
$refl = getReflectionFunction($functionName);
1112
if (!$refl) {

bin/gen_callmap_utils.php

-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,5 @@ function writeCallMap(string $file, array $callMap): void
199199
BypassFinals::enable();
200200

201201
new ProjectAnalyzer(new TestConfig, new Providers(new FileProvider));
202-
$callMap = require "dictionaries/CallMap.php";
203-
$orig = $callMap;
204202

205203
$codebase = ProjectAnalyzer::getInstance()->getCodebase();

bin/normalize-callmap.php

+57-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,63 @@
22

33
declare(strict_types=1);
44

5+
use Webmozart\Assert\Assert;
6+
57
require __DIR__ . '/gen_callmap_utils.php';
68

7-
foreach (glob(__DIR__."/../dictionaries/CallMap*.php") as $file) {
8-
$callMap = require $file;
9-
$callMap = normalizeCallMap($callMap);
10-
writeCallMap($file, $callMap);
9+
$baseMaps = [];
10+
11+
foreach (glob(__DIR__."/../dictionaries/base/CallMap_*.php") as $file) {
12+
Assert::eq(preg_match('/_(\d+)\.php/', $file, $matches), 1);
13+
$version = $matches[1];
14+
15+
$baseMaps[$version] = normalizeCallMap(require $file);
16+
}
17+
18+
ksort($baseMaps);
19+
$last = array_key_last($baseMaps);
20+
21+
$customMaps = [
22+
$last => normalizeCallMap(require __DIR__."/../dictionaries/override/CallMap.php")
23+
];
24+
25+
$diffs = [];
26+
foreach (glob(__DIR__."/../dictionaries/override/CallMap_*.php") as $file) {
27+
Assert::eq(preg_match('/_(\d+)_delta\.php/', $file, $matches), 1);
28+
$version = $matches[1];
29+
$diffs[$version] = normalizeCallMap(require $file);
1130
}
31+
krsort($diffs);
32+
33+
$versions = array_reverse(array_keys($diffs));
34+
35+
foreach ($diffs as $version => $diff) {
36+
$callMap = $customMaps[$version];
37+
$diff = normalizeCallMap(require $file);
38+
foreach ($diff['removed'] as $func => $descr) {
39+
$callMap[$func] = $descr;
40+
}
41+
foreach ($diff['added'] as $func => $descr) {
42+
unset($callMap[$func]);
43+
}
44+
foreach ($diff['changed'] as $func => $sub) {
45+
$callMap[$func] = $sub['old'];
46+
}
47+
48+
$prevVersion = array_search($version, $versions)-1;
49+
if ($prevVersion < 0) {
50+
continue;
51+
}
52+
$customMaps[$versions[$prevVersion]] = $callMap;
53+
}
54+
55+
foreach ($customMaps as $version => $data) {
56+
foreach ($data as $name => $func) {
57+
if (($baseMaps[$version][$name] ?? null) === $func) {
58+
unset($customMaps[$version][$name]);
59+
} else if(($baseMaps[$version][$name] ?? null))
60+
var_dump($name, ($baseMaps[$version][$name] ?? null), $func);
61+
}
62+
}
63+
64+
var_dump($customMaps);

0 commit comments

Comments
 (0)