Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unstable hasFullyQualified(Interface|Enum)() #10603

Merged
merged 6 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2406,7 +2406,6 @@ public function getKeyValueParamsForTraversableObject(Atomic $type): array

/**
* @param array<string, mixed> $phantom_classes
* @psalm-suppress PossiblyUnusedMethod part of the public API
*/
public function queueClassLikeForScanning(
string $fq_classlike_name,
Expand Down
11 changes: 7 additions & 4 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ public function hasFullyQualifiedClassName(
}
}

// fixme: this looks like a crazy caching hack
if (!isset($this->existing_classes_lc[$fq_class_name_lc])
|| !$this->existing_classes_lc[$fq_class_name_lc]
|| !$this->classlike_storage_provider->has($fq_class_name_lc)
Expand Down Expand Up @@ -396,13 +397,14 @@ public function hasFullyQualifiedInterfaceName(
): bool {
$fq_class_name_lc = strtolower($this->getUnAliasedName($fq_class_name));

// fixme: this looks like a crazy caching hack
if (!isset($this->existing_interfaces_lc[$fq_class_name_lc])
|| !$this->existing_interfaces_lc[$fq_class_name_lc]
|| !$this->classlike_storage_provider->has($fq_class_name_lc)
) {
if ((
!isset($this->existing_classes_lc[$fq_class_name_lc])
|| $this->existing_classes_lc[$fq_class_name_lc]
!isset($this->existing_interfaces_lc[$fq_class_name_lc])
|| $this->existing_interfaces_lc[$fq_class_name_lc]
)
&& !$this->classlike_storage_provider->has($fq_class_name_lc)
) {
Expand Down Expand Up @@ -463,13 +465,14 @@ public function hasFullyQualifiedEnumName(
): bool {
$fq_class_name_lc = strtolower($this->getUnAliasedName($fq_class_name));

// fixme: this looks like a crazy caching hack
if (!isset($this->existing_enums_lc[$fq_class_name_lc])
|| !$this->existing_enums_lc[$fq_class_name_lc]
|| !$this->classlike_storage_provider->has($fq_class_name_lc)
) {
if ((
!isset($this->existing_classes_lc[$fq_class_name_lc])
|| $this->existing_classes_lc[$fq_class_name_lc]
!isset($this->existing_enums_lc[$fq_class_name_lc])
|| $this->existing_enums_lc[$fq_class_name_lc]
)
&& !$this->classlike_storage_provider->has($fq_class_name_lc)
) {
Expand Down
6 changes: 4 additions & 2 deletions tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
use function array_shift;
use function class_exists;
use function count;
use function enum_exists;
use function explode;
use function function_exists;
use function in_array;
use function interface_exists;
use function is_array;
use function is_int;
use function json_encode;
Expand Down Expand Up @@ -140,7 +142,6 @@ class InternalCallMapHandlerTest extends TestCase
'oci_result',
'ocigetbufferinglob',
'ocisetbufferinglob',
'recursiveiteratoriterator::__construct', // Class used in CallMap does not exist: recursiveiterator
'sqlsrv_fetch_array',
'sqlsrv_fetch_object',
'sqlsrv_get_field',
Expand Down Expand Up @@ -173,7 +174,6 @@ class InternalCallMapHandlerTest extends TestCase
private static array $ignoredReturnTypeOnlyFunctions = [
'appenditerator::getinneriterator' => ['8.1', '8.2', '8.3'],
'appenditerator::getiteratorindex' => ['8.1', '8.2', '8.3'],
'arrayobject::getiterator' => ['8.1', '8.2', '8.3'],
'cachingiterator::getinneriterator' => ['8.1', '8.2', '8.3'],
'callbackfilteriterator::getinneriterator' => ['8.1', '8.2', '8.3'],
'curl_multi_getcontent',
Expand Down Expand Up @@ -631,6 +631,8 @@ private function assertTypeValidity(ReflectionType $reflected, string $specified
} catch (InvalidArgumentException $e) {
if (preg_match('/^Could not get class storage for (.*)$/', $e->getMessage(), $matches)
&& !class_exists($matches[1])
&& !interface_exists($matches[1])
&& !enum_exists($matches[1])
) {
$this->fail("Class used in CallMap does not exist: {$matches[1]}");
}
Expand Down
1 change: 1 addition & 0 deletions tests/TypeReconciliation/ReconcilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class A {}
class B {}
interface SomeInterface {}
');
$this->project_analyzer->getCodebase()->queueClassLikeForScanning('Countable');
$this->project_analyzer->getCodebase()->scanFiles();
}

Expand Down