Skip to content

Fix PHPStan alreadyNarrowedType error in value-limit test - #295

Merged
oschwald merged 1 commit into
mainfrom
wstorey/fix-phpstan-already-narrowed
Sep 28, 2026
Merged

oschwald merged 1 commit into
mainfrom
wstorey/fix-phpstan-already-narrowed

Conversation

@horgh

@horgh horgh commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

PHPStan 2.2.16 fails the scheduled lint run on main (run). It remembers the result of $reader->get('1.1.1.1') after the first assertSame(), so it reports the second, identical assertion as always true.

This change stores each lookup result in its own variable. The test still does two lookups on the same reader.

PHPStan 2.2.16 reports no errors with this change.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Updated a test to verify that consecutive lookups each return the expected results.

PHPStan 2.2.16 remembers the result of a method call after an
assertion. It reported the second assertSame() on the same get() call
as always true. Store each lookup result in its own variable so that
PHPStan checks both results.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 27, 2026 19:06
@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 6e0c39a9-76bf-478d-b952-4ce41c519ab3

📥 Commits

Reviewing files that changed from the base of the PR and between 8a1f03e and c1f670c.

📒 Files selected for processing (1)
  • tests/MaxMind/Db/Test/ReaderTest.php

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The limit test now stores the results of two consecutive lookups in separate variables before asserting that each matches the expected array. The expected behavior is unchanged.

Changes

Limit lookup test

Layer / File(s) Summary
Capture and assert lookup results
tests/MaxMind/Db/Test/ReaderTest.php
The test stores both lookup results in separate variables, then checks each against the expected array.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~2 minutes

Change: Refactor

Suggested reviewers: oschwald

Merge Risk: ⚪ Minimal · up to c1f67

This change only reorganizes the limit test’s two lookups and assertions; no production behavior change or merge-blocking risk is identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing the PHPStan alreadyNarrowedType error in the value-limit test.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each lookup twice,
Then stores the finds in tidy rows.
Two arrays match the expected prize,
As quietly the test now goes.
One hop, one check, and off it goes!

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The targeted test change resolves the PHPStan error without altering intended behavior.

Review effort: Lite
Findings: None

What changed in this PR

Updates the value-limit test to avoid PHPStan’s repeated-expression narrowing error while preserving both lookups.

Changes:

  • Stores each lookup result separately.
  • Asserts both results against the expected value.
File Description
tests/​MaxMind/​Db/​Test/​ReaderTest.php Adjusts lookup assertions for PHPStan compatibility.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@oschwald
oschwald merged commit 4582e39 into main Sep 28, 2026
126 checks passed
@oschwald
oschwald deleted the wstorey/fix-phpstan-already-narrowed branch September 28, 2026 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants