Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jul 24, 2023
1 parent a2e4961 commit 79da332
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 50 deletions.
15 changes: 14 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="dev-master@841cccd693a15da70c034a55eb05ee7ed8fdbc22">
<files psalm-version="dev-master@2e5235a0be1f106c251f69b4943ae4f027cef761">
<file src="examples/TemplateChecker.php">
<PossiblyUndefinedIntArrayOffset>
<code><![CDATA[$comment_block->tags['variablesfrom'][0]]]></code>
Expand Down Expand Up @@ -290,6 +290,19 @@
<code><![CDATA[$stmt->props[0]]]></code>
</PossiblyUndefinedIntArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/LanguageClient.php">
<InvalidArrayAccess>
<code>$config</code>
</InvalidArrayAccess>
<InvalidArrayOffset>
<code>[$config]</code>
</InvalidArrayOffset>
</file>
<file src="src/Psalm/Internal/LanguageServer/LanguageServer.php">
<MixedAssignment>
<code>$result</code>
</MixedAssignment>
</file>
<file src="src/Psalm/Internal/MethodIdentifier.php">
<PossiblyUndefinedIntArrayOffset>
<code>$method_id_parts[1]</code>
Expand Down
2 changes: 0 additions & 2 deletions src/Psalm/Internal/Algebra/FormulaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ public static function getFormula(
$redefined = false;

if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
Expand Down Expand Up @@ -420,7 +419,6 @@ public static function getFormula(
$redefined = false;

if ($var[0] === '=') {
/** @var string */
$var = substr($var, 1);
$redefined = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Psalm/Internal/Analyzer/NamespaceAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = "\\";
Expand All @@ -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;
}

Expand Down
1 change: 0 additions & 1 deletion src/Psalm/Internal/Codebase/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
13 changes: 7 additions & 6 deletions src/Psalm/Internal/LanguageServer/LanguageClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int, object> $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');
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
$values,
);

assert($result !== false);

if (!$result) {
return Type::getEmptyArray();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Type/Reconciler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion tests/Internal/Codebase/InternalCallMapHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 0 additions & 2 deletions tests/LanguageServer/MockProtocolStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down

0 comments on commit 79da332

Please sign in to comment.