Skip to content

Commit

Permalink
cs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jan 18, 2025
1 parent 1154dcc commit 0c4ad45
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 23 deletions.
12 changes: 12 additions & 0 deletions bin/gen_callmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@

declare(strict_types=1);

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

require 'vendor/autoload.php';
require __DIR__ . '/gen_callmap_utils.php';

BypassFinals::enable();

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

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

// Load+normalize autogenerated maps
$baseMaps = [];
foreach (glob(__DIR__."/../dictionaries/autogen/CallMap_*.php") as $file) {
Expand Down
37 changes: 16 additions & 21 deletions bin/gen_callmap_utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@

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\Internal\Codebase\Reflection;
use Psalm\Internal\Type\Comparator\UnionTypeComparator;
use Psalm\Type;
use Psalm\Type\Atomic\TNull;

function internalNormalizeCallMap(array|string $callMap, string|int $key = 0): array|string
{
Expand Down Expand Up @@ -125,9 +122,9 @@ function assertEntryParameters(ReflectionFunctionAbstract $function, array &$ent
}
}

/**
* @param array{byRef: bool, name?: string, refMode: 'rw'|'w'|'r', variadic: bool, optional: bool, type: string} $normalizedEntry
*/
/**
* @param array{byRef: bool, name?: string, refMode: 'rw'|'w'|'r', variadic: bool, optional: bool, type: string} $normalizedEntry
*/
function assertParameter(array &$normalizedEntry, ReflectionParameter $param): void
{
$name = $param->getName();
Expand Down Expand Up @@ -163,7 +160,16 @@ function assertTypeValidity(ReflectionType $reflected, string &$specified, strin

$codebase = ProjectAnalyzer::getInstance()->getCodebase();
try {
if (!UnionTypeComparator::isContainedBy($codebase, $callMapType, $expectedType, false, false, null, false, false) && !str_contains($specified, 'static')) {
if (!UnionTypeComparator::isContainedBy(
$codebase,
$callMapType,
$expectedType,
false,
false,
null,
false,
false,
) && !str_contains($specified, 'static')) {
$specified = $expectedType->getId(true);
$callMapType = $expectedType;
}
Expand All @@ -182,10 +188,6 @@ function assertTypeValidity(ReflectionType $reflected, string &$specified, strin
}
}
$specified = $callMapType->getId(true);
// //$this->assertSame($expectedType->hasBool(), $callMapType->hasBool(), "{$msgPrefix} type '{$specified}' missing bool from reflected type '{$reflected}'");
// $this->assertSame($expectedType->hasArray(), $callMapType->hasArray(), "{$msgPrefix} type '{$specified}' missing array from reflected type '{$reflected}'");
// $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
Expand All @@ -194,10 +196,3 @@ function writeCallMap(string $file, array $callMap): void
return '.var_export($callMap, true).';');
}


BypassFinals::enable();

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

$codebase = ProjectAnalyzer::getInstance()->getCodebase();
5 changes: 4 additions & 1 deletion src/Psalm/Internal/Codebase/InternalCallMapHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,10 @@ public static function getCallMap(): array
return self::$call_map;
}

$analyzer_version_int = max(self::MIN_CALLMAP_VERSION, (int) ($analyzer_major_version . $analyzer_minor_version));
$analyzer_version_int = max(
self::MIN_CALLMAP_VERSION,
(int) ($analyzer_major_version . $analyzer_minor_version),
);

/** @var non-empty-array<lowercase-string, array<int|string, string>> */
$call_map = require(dirname(__DIR__, 4) . "/dictionaries/CallMap_$analyzer_version_int.php");
Expand Down
4 changes: 3 additions & 1 deletion src/Psalm/Internal/Codebase/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ public function registerFunction(string $function_id): ?bool
}

if ($reflection_return_type = (PHP_VERSION_ID >= 80100 ? (
$reflection_function->getTentativeReturnType() ?? $reflection_function->getReturnType()
($reflection_function->getTentativeReturnType()
?? $reflection_function->getReturnType()
)
) : $reflection_function->getReturnType())) {
$storage->return_type = self::getPsalmTypeFromReflectionType($reflection_return_type);
}
Expand Down

0 comments on commit 0c4ad45

Please sign in to comment.