Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Feb 14, 2025
1 parent 516f8fa commit cdb2fd2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
33 changes: 33 additions & 0 deletions bin/stubs/gen_callmap_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

declare(strict_types=1);

use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use Psalm\Internal\Analyzer\ProjectAnalyzer;
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
use Psalm\Type;
Expand Down Expand Up @@ -248,3 +250,34 @@ function get_changed_functions(array $a, array $b): array

return $changed_functions;
}

function extractClassesFromStatements(array $statements): array
{
$classes = [];
foreach ($statements as $statement) {
if ($statement instanceof Class_) {
$classes[strtolower($statement->namespacedName->toString())] = true;
}
if ($statement instanceof Namespace_) {
$classes += extractClassesFromStatements($statement->stmts);
}
}

return $classes;
}

function serializeArray(array $array, string $prefix): string
{
uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second));
$result = "[\n";
$localPrefix = $prefix . ' ';
foreach ($array as $key => $value) {
$result .= $localPrefix . var_export((string) $key, true) . ' => ' .
(is_array($value)
? serializeArray($value, $localPrefix)
: var_export($value, true)) . ",\n";
}
$result .= $prefix . ']';

return $result;
}
36 changes: 2 additions & 34 deletions bin/stubs/update-property-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
//
// What we are currently missing is properly parsing of <xi:include> directives.

use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\ParserFactory;
Expand All @@ -21,32 +19,18 @@
throw new ErrorException($str, 0, $num, $file, $line);
});

foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php'] as $file) {
foreach ([__DIR__ . '/../../../../autoload.php', __DIR__ . '/../../vendor/autoload.php'] as $file) {
if (file_exists($file)) {
require $file;
break;
}
}
require __DIR__ . '/gen_callmap_utils.php';

$parser = (new ParserFactory)->createForNewestSupportedVersion();
$traverser = new NodeTraverser();
$traverser->addVisitor(new NameResolver);

function extractClassesFromStatements(array $statements): array
{
$classes = [];
foreach ($statements as $statement) {
if ($statement instanceof Class_) {
$classes[strtolower($statement->namespacedName->toString())] = true;
}
if ($statement instanceof Namespace_) {
$classes += extractClassesFromStatements($statement->stmts);
}
}

return $classes;
}

$stubbedClasses = [];
foreach (new RecursiveDirectoryIterator(
__DIR__ . '/../stubs',
Expand Down Expand Up @@ -161,22 +145,6 @@ function extractClassesFromStatements(array $statements): array
}
}

function serializeArray(array $array, string $prefix): string
{
uksort($array, fn(string $first, string $second): int => strtolower($first) <=> strtolower($second));
$result = "[\n";
$localPrefix = $prefix . ' ';
foreach ($array as $key => $value) {
$result .= $localPrefix . var_export((string) $key, true) . ' => ' .
(is_array($value)
? serializeArray($value, $localPrefix)
: var_export($value, true)) . ",\n";
}
$result .= $prefix . ']';

return $result;
}

$serialized = serializeArray($classes, '');
file_put_contents(
dirname(__DIR__) . '/dictionaries/PropertyMap.php',
Expand Down

0 comments on commit cdb2fd2

Please sign in to comment.