Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 1, 2024
1 parent 8cfb3c1 commit 6b9f365
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bin/gen_base_callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function paramsToEntries(ReflectionFunctionAbstract $reflectionFunction): array

$args = paramsToEntries($func);

$callmap[$name] = $args;
$callmap[strtolower($name)] = $args;
}

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

$callmap[$class.'::'.$method->getName()] = $args;
$callmap[strtolower($class.'::'.$method->getName())] = $args;
}
}

Expand Down
5 changes: 3 additions & 2 deletions bin/gen_callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

declare(strict_types=1);

// Written by SamMousa in https://github.com/vimeo/psalm/issues/8101, finalized by @danog

require __DIR__ . '/gen_callmap_utils.php';

$callMap = require "dictionaries/CallMap.php";
$orig = $callMap;

foreach ($callMap as $functionName => &$entry) {
$refl = getReflectionFunction($functionName);
if (!$refl) {
Expand Down
2 changes: 0 additions & 2 deletions bin/gen_callmap_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,5 @@ function writeCallMap(string $file, array $callMap): void
BypassFinals::enable();

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

$codebase = ProjectAnalyzer::getInstance()->getCodebase();
61 changes: 57 additions & 4 deletions bin/normalize-callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,63 @@

declare(strict_types=1);

use Webmozart\Assert\Assert;

require __DIR__ . '/gen_callmap_utils.php';

foreach (glob(__DIR__."/../dictionaries/CallMap*.php") as $file) {
$callMap = require $file;
$callMap = normalizeCallMap($callMap);
writeCallMap($file, $callMap);
$baseMaps = [];

foreach (glob(__DIR__."/../dictionaries/base/CallMap_*.php") as $file) {
Assert::eq(preg_match('/_(\d+)\.php/', $file, $matches), 1);
$version = $matches[1];

$baseMaps[$version] = normalizeCallMap(require $file);
}

ksort($baseMaps);
$last = array_key_last($baseMaps);

$customMaps = [
$last => normalizeCallMap(require __DIR__."/../dictionaries/override/CallMap.php")
];

$diffs = [];
foreach (glob(__DIR__."/../dictionaries/override/CallMap_*.php") as $file) {
Assert::eq(preg_match('/_(\d+)_delta\.php/', $file, $matches), 1);
$version = $matches[1];
$diffs[$version] = normalizeCallMap(require $file);
}
krsort($diffs);

$versions = array_reverse(array_keys($diffs));

foreach ($diffs as $version => $diff) {
$callMap = $customMaps[$version];
$diff = normalizeCallMap(require $file);
foreach ($diff['removed'] as $func => $descr) {
$callMap[$func] = $descr;
}
foreach ($diff['added'] as $func => $descr) {
unset($callMap[$func]);
}
foreach ($diff['changed'] as $func => $sub) {
$callMap[$func] = $sub['old'];
}

$prevVersion = array_search($version, $versions)-1;
if ($prevVersion < 0) {
continue;
}
$customMaps[$versions[$prevVersion]] = $callMap;
}

foreach ($customMaps as $version => $data) {
foreach ($data as $name => $func) {
if (($baseMaps[$version][$name] ?? null) === $func) {
unset($customMaps[$version][$name]);
} else if(($baseMaps[$version][$name] ?? null))
var_dump($name, ($baseMaps[$version][$name] ?? null), $func);
}
}

var_dump($customMaps);

0 comments on commit 6b9f365

Please sign in to comment.