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

PHPLIB-1119: Update to Psalm 5 #1131

Merged
merged 5 commits into from
Jul 18, 2023
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"rector/rector": "^0.16.0",
"squizlabs/php_codesniffer": "^3.7",
"symfony/phpunit-bridge": "^5.2",
"vimeo/psalm": "^4.28"
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": { "MongoDB\\": "src/" },
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/csfle-explicit_encryption.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

/* Using the client configured without encryption, find the document and observe
* that the field is not automatically decrypted. */

/** @var object{encryptedField: Binary} $document */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at psalm-baseline.xml, this was not enough to enforce the type of $document->encryptedField?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error is regarding the return type of decrypt, which is mixed and can't be made any more specific:

ERROR: MixedArgument - docs/examples/csfle-explicit_encryption.php:51:27 - Argument 2 of printf cannot be mixed, expecting float|int|string

The @var annotation here prevents a different Psalm error regarding accessing a potentially undefined property.

$document = $collection->findOne();

print_r($document);
Expand Down
2 changes: 1 addition & 1 deletion examples/changestream.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function toJSON(object $document): string
$changeStream->next();

if (time() - $startTime > 3) {
printf("Aborting after 3 seconds...\n");
echo "Aborting after 3 seconds...\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Psalm object to using printf() with a single argument, or did you do this on your own?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Psalm objected to this, complaining that printf needs two arguments.

break;
}
}
6 changes: 3 additions & 3 deletions examples/command_logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public function commandStarted(CommandStartedEvent $event): void
printf("%s command started\n", $event->getCommandName());

printf("command: %s\n", toJson($event->getCommand()));
printf("\n");
echo "\n";
}

public function commandSucceeded(CommandSucceededEvent $event): void
{
printf("%s command succeeded\n", $event->getCommandName());
printf("reply: %s\n", toJson($event->getReply()));
printf("\n");
echo "\n";
}

public function commandFailed(CommandFailedEvent $event): void
Expand All @@ -50,7 +50,7 @@ public function commandFailed(CommandFailedEvent $event): void
printf("exception: %s\n", get_class($exception));
printf("exception.code: %d\n", $exception->getCode());
printf("exception.message: %s\n", $exception->getMessage());
printf("\n");
echo "\n";
}
}

Expand Down
Loading