diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 69c51858103..b299a6eedbe 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + tags['variablesfrom'][0]]]> @@ -290,6 +290,19 @@ props[0]]]> + + + $config + + + [$config] + + + + + $result + + $method_id_parts[1] diff --git a/src/Psalm/Internal/Algebra/FormulaGenerator.php b/src/Psalm/Internal/Algebra/FormulaGenerator.php index c5d75f8829c..9c5482c4a57 100644 --- a/src/Psalm/Internal/Algebra/FormulaGenerator.php +++ b/src/Psalm/Internal/Algebra/FormulaGenerator.php @@ -149,7 +149,6 @@ public static function getFormula( $redefined = false; if ($var[0] === '=') { - /** @var string */ $var = substr($var, 1); $redefined = true; } @@ -420,7 +419,6 @@ public static function getFormula( $redefined = false; if ($var[0] === '=') { - /** @var string */ $var = substr($var, 1); $redefined = true; } diff --git a/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php b/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php index a01318a3e81..e08bffbe29e 100644 --- a/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php @@ -244,7 +244,7 @@ public static function getIdentifierParts(string $identifier): array while (($pos = strpos($identifier, "\\")) !== false) { if ($pos > 0) { $part = substr($identifier, 0, $pos); - assert(is_string($part) && $part !== ""); + assert($part !== ""); $parts[] = $part; } $parts[] = "\\"; @@ -253,13 +253,13 @@ public static function getIdentifierParts(string $identifier): array if (($pos = strpos($identifier, "::")) !== false) { if ($pos > 0) { $part = substr($identifier, 0, $pos); - assert(is_string($part) && $part !== ""); + assert($part !== ""); $parts[] = $part; } $parts[] = "::"; $identifier = substr($identifier, $pos + 2); } - if ($identifier !== "" && $identifier !== false) { + if ($identifier !== "") { $parts[] = $identifier; } diff --git a/src/Psalm/Internal/Codebase/Reflection.php b/src/Psalm/Internal/Codebase/Reflection.php index f62cfdc7e28..06f6178844b 100644 --- a/src/Psalm/Internal/Codebase/Reflection.php +++ b/src/Psalm/Internal/Codebase/Reflection.php @@ -426,7 +426,6 @@ public static function getPsalmTypeFromReflectionType(?ReflectionType $reflectio if ($reflection_type instanceof ReflectionNamedType) { $type = $reflection_type->getName(); } elseif ($reflection_type instanceof ReflectionUnionType) { - /** @psalm-suppress MixedArgument */ $type = implode( '|', array_map( diff --git a/src/Psalm/Internal/LanguageServer/LanguageClient.php b/src/Psalm/Internal/LanguageServer/LanguageClient.php index 0aed33950a6..c3f5d60b2f4 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageClient.php +++ b/src/Psalm/Internal/LanguageServer/LanguageClient.php @@ -9,6 +9,7 @@ use LanguageServerProtocol\LogTrace; use Psalm\Internal\LanguageServer\Client\TextDocument as ClientTextDocument; use Psalm\Internal\LanguageServer\Client\Workspace as ClientWorkspace; +use Revolt\EventLoop; use function is_null; use function json_decode; @@ -65,13 +66,13 @@ public function refreshConfiguration(): void { $capabilities = $this->server->clientCapabilities; if ($capabilities->workspace->configuration ?? false) { - $this->workspace->requestConfiguration('psalm')->onResolve(function ($error, $value): void { - if ($error) { - $this->server->logError('There was an error getting configuration'); - } else { - /** @var array $value */ - [$config] = $value; + EventLoop::queue(function () { + try { + /** @var object $config */ + [$config] = $this->workspace->requestConfiguration('psalm'); $this->configurationRefreshed((array) $config); + } catch (\Throwable) { + $this->server->logError('There was an error getting configuration'); } }); } diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayCombineReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayCombineReturnTypeProvider.php index 88125e398e3..999f0b84ef5 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayCombineReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayCombineReturnTypeProvider.php @@ -121,8 +121,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev $values, ); - assert($result !== false); - if (!$result) { return Type::getEmptyArray(); } diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/SprintfReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/SprintfReturnTypeProvider.php index 8c9af9410bc..925bc0c1a92 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/SprintfReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/SprintfReturnTypeProvider.php @@ -201,35 +201,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev } } - if ($result === false && count($dummy) === $provided_placeholders_count) { - // could be invalid format or too few arguments - // we cannot distinguish this in PHP 7 without additional checks - $max_dummy = array_fill(0, 100, ''); - $result = @sprintf($type->getSingleStringLiteral()->value, ...$max_dummy); - if ($result === false) { - // the format is invalid - IssueBuffer::maybeAdd( - new InvalidArgument( - 'Argument 1 of ' . $event->getFunctionId() . ' is invalid', - $event->getCodeLocation(), - $event->getFunctionId(), - ), - $statements_source->getSuppressedIssues(), - ); - } else { - IssueBuffer::maybeAdd( - new TooFewArguments( - 'Too few arguments for ' . $event->getFunctionId(), - $event->getCodeLocation(), - $event->getFunctionId(), - ), - $statements_source->getSuppressedIssues(), - ); - } - - return Type::getFalse(); - } - // we can only validate the format and arg 1 when using splat if ($has_splat_args === true) { break; @@ -264,13 +235,13 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev return null; } - if ($initial_result !== null && $initial_result !== false && $initial_result !== '') { + if ($initial_result !== null && $initial_result !== '') { return Type::getNonEmptyString(); } // if we didn't have any valid result // the pattern is invalid or not yet supported by the return type provider - if ($initial_result === null || $initial_result === false) { + if ($initial_result === null) { return null; } diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index 074ef233ab3..8d36c9990db 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -1109,7 +1109,7 @@ private static function adjustTKeyedArrayType( $base_key = implode($key_parts); - if (isset($existing_types[$base_key]) && $array_key_offset !== false) { + if (isset($existing_types[$base_key]) && $array_key_offset !== '') { foreach ($existing_types[$base_key]->getAtomicTypes() as $base_atomic_type) { if ($base_atomic_type instanceof TList) { $base_atomic_type = $base_atomic_type->getKeyedArray(); diff --git a/tests/Internal/Codebase/InternalCallMapHandlerTest.php b/tests/Internal/Codebase/InternalCallMapHandlerTest.php index b21fc991a6b..58420c14400 100644 --- a/tests/Internal/Codebase/InternalCallMapHandlerTest.php +++ b/tests/Internal/Codebase/InternalCallMapHandlerTest.php @@ -606,7 +606,6 @@ private function assertParameter(array $normalizedEntry, ReflectionParameter $pa public function assertEntryReturnType(ReflectionFunctionAbstract $function, string $entryReturnType): void { if (version_compare(PHP_VERSION, '8.1.0', '>=')) { - /** @var ReflectionType|null $expectedType */ $expectedType = $function->hasTentativeReturnType() ? $function->getTentativeReturnType() : $function->getReturnType(); } else { $expectedType = $function->getReturnType(); diff --git a/tests/LanguageServer/MockProtocolStream.php b/tests/LanguageServer/MockProtocolStream.php index b95704d8c82..f3db6aebd95 100644 --- a/tests/LanguageServer/MockProtocolStream.php +++ b/tests/LanguageServer/MockProtocolStream.php @@ -19,8 +19,6 @@ class MockProtocolStream implements ProtocolReader, ProtocolWriter, EmitterInter use EmitterTrait; /** * Sends a Message to the client - * - * @psalm-suppress PossiblyUnusedReturnValue */ public function write(Message $msg): void {