Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Dec 1, 2024
1 parent 64f4efc commit 1d45aa8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 46 deletions.
8 changes: 7 additions & 1 deletion bin/gen_base_callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@
}

foreach (get_declared_classes() as $class) {
foreach ((new ReflectionClass($class))->getMethods() as $method) {
$refl = new ReflectionClass($class);
if (!$refl->isInternal()) {
continue;
}

foreach ($refl->getMethods() as $method) {
$args = paramsToEntries($method);

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

$callmap = normalizeCallMap($callmap);
var_dump($callmap);
23 changes: 0 additions & 23 deletions bin/gen_callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,8 @@

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

require 'vendor/autoload.php';

require __DIR__ . '/gen_callmap_utils.php';

use DG\BypassFinals;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Provider\FileProvider;
use Psalm\Internal\Provider\Providers;
use Psalm\Tests\TestConfig;

BypassFinals::enable();

function writeCallMap(string $file, array $callMap): void
{
file_put_contents($file, '<?php // phpcs:ignoreFile
return '.var_export($callMap, true).';');
}

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

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

foreach ($callMap as $functionName => &$entry) {
$refl = getReflectionFunction($functionName);
if (!$refl) {
Expand Down
23 changes: 23 additions & 0 deletions bin/gen_callmap_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

declare(strict_types=1);

require 'vendor/autoload.php';

use DG\BypassFinals;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Provider\FileProvider;
use Psalm\Internal\Provider\Providers;
use Psalm\Tests\TestConfig;
use Psalm\Type;

function internalNormalizeCallMap(array|string $callMap): array|string {
Expand Down Expand Up @@ -227,3 +234,19 @@ function assertTypeValidity(ReflectionType $reflected, string &$specified, strin
// $this->assertSame($expectedType->hasInt(), $callMapType->hasInt(), "{$msgPrefix} type '{$specified}' missing int from reflected type '{$reflected}'");
// $this->assertSame($expectedType->hasFloat(), $callMapType->hasFloat(), "{$msgPrefix} type '{$specified}' missing float from reflected type '{$reflected}'");
}

function writeCallMap(string $file, array $callMap): void
{
file_put_contents($file, '<?php // phpcs:ignoreFile
return '.var_export($callMap, true).';');
}


BypassFinals::enable();

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

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

declare(strict_types=1);

require 'vendor/autoload.php';

require __DIR__ . '/gen_callmap_utils.php';

use DG\BypassFinals;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Provider\FileProvider;
use Psalm\Internal\Provider\Providers;
use Psalm\Tests\TestConfig;
use Psalm\Type;

BypassFinals::enable();

new ProjectAnalyzer(new TestConfig, new Providers(new FileProvider));

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

chdir(__DIR__.'/../');

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

file_put_contents($file, '<?php // phpcs:ignoreFile
return '.var_export($callMap, true).';');
writeCallMap($file, $callMap);
}

0 comments on commit 1d45aa8

Please sign in to comment.