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-1372 Fix RiskyTruthyFalsyComparison #1218

Merged
merged 2 commits into from
Jan 24, 2024
Merged

Conversation

GromNaN
Copy link
Member

@GromNaN GromNaN commented Jan 22, 2024

Fix PHPLIB-1372

The new RiskyTruthyFalsyComparison errors are introduced by psalm 5.20.0.

  • Disable on example files. Using getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1/' is safe as any falsy value could be replaced by the default URI.
  • Replace !empty($filter) by $filter !== [] as $filter is an array or an object, and even empty(new stdClass) is true. This might be a necessary bug fix.

@GromNaN GromNaN requested review from jmikola and alcaeus January 22, 2024 13:42
src/ChangeStream.php Outdated Show resolved Hide resolved
Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

I'll defer you on @alcaeus' suggestion.

@@ -187,7 +187,7 @@ private function createCommandDocument(): array
{
$cmd = ['count' => $this->collectionName];

if (! empty($this->filter)) {
if ($this->filter !== []) {
Copy link
Member

@jmikola jmikola Jan 22, 2024

Choose a reason for hiding this comment

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

$filter is an array or an object, and even empty(new stdClass) is true. This might be a necessary bug fix.

The count and distinct commands both use an empty filter by default, so including new stdClass in the outgoing command was inconsistent (and redundant) but had no functional impact on the result.

I don't think we need to go the extra mile to detect empty objects, so if this is the most concise change to silence Psalm that works for me.

Co-authored-by: Andreas Braun <[email protected]>
@GromNaN GromNaN merged commit c45e727 into mongodb:master Jan 24, 2024
24 checks passed
@GromNaN GromNaN deleted the PHPLIB-1372 branch January 24, 2024 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants