Skip to content

refactor: add null guards in db mappers and fix JsonResponse return type for Psalm 6#12874

Open
ChristophWurst wants to merge 1 commit into
mainfrom
fix/psalm-6-null-guards
Open

refactor: add null guards in db mappers and fix JsonResponse return type for Psalm 6#12874
ChristophWurst wants to merge 1 commit into
mainfrom
fix/psalm-6-null-guards

Conversation

@ChristophWurst
Copy link
Copy Markdown
Member

@ChristophWurst ChristophWurst commented May 5, 2026

Summary

  • LocalMessageMapper: add null guard for getLocalMessageId() before using as array key in getAllForUser, findDue, findDueDrafts; use ?? [] for getRecipients() in updateWithRecipients
  • MessageMapper: extract getMessageId() to a local variable with null guard before using as array key in updateTags and findRelatedData
  • JsonResponse: align @return static@return self on errorFromThrowable to match the actual PHP return type hint

These are Psalm 6 PossiblyNullArrayOffset and MoreSpecificReturnType errors that remain after the Psalm v6 upgrade in #11224.

Test plan

  • PHP unit tests pass (composer test:unit)
  • Psalm static analysis passes (composer psalm)

Part of #11224

…ype for Psalm 6

- LocalMessageMapper: guard getLocalMessageId() before using as array key in
  findAll, findDue, findDueDrafts; use ?? [] for getRecipients()
- MessageMapper: extract getMessageId() to variable with null guard before
  using as array key in updateTags and findRelatedData
- JsonResponse: align @return static → @return self on errorFromThrowable
  to match actual return type hint

AI-assisted: Claude Code (claude-sonnet-4-6)
Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com>
@ChristophWurst
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c2e2dbe9-e4dd-4509-8c7a-8e2a4847a770

📥 Commits

Reviewing files that changed from the base of the PR and between cf0f574 and 19af1af.

📒 Files selected for processing (3)
  • lib/Db/LocalMessageMapper.php
  • lib/Db/MessageMapper.php
  • lib/Http/JsonResponse.php

📝 Walkthrough

Walkthrough

This PR addresses null-safety in data mapper operations by preventing null keys from being used in array lookups across three database mapper classes. In LocalMessageMapper, three query methods now skip recipient and attachment rows where localMessageId is null before building their maps, and updateWithRecipients() normalizes nullable recipients to an empty array. In MessageMapper, both updateTags() and findRelatedData() now check for non-null message_id before accessing the tags map. Additionally, a PHPDoc annotation in JsonResponse::errorFromThrowable() is updated from static to self.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main changes: adding null guards in db mappers and fixing JsonResponse return type annotation for Psalm 6 compatibility.
Description check ✅ Passed The description comprehensively covers all changes across the three modified files, explains the purpose (addressing Psalm 6 errors), and confirms testing has passed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🏗️ In progress

Development

Successfully merging this pull request may close these issues.

1 participant