Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jul 21, 2025

Q A
Is bugfix?
New feature? ✔️
Breaks BC?

Summary by CodeRabbit

  • New Features

    • Enhanced request handling with support for PSR-7 ServerRequest interoperability and worker mode environments.
    • Added methods to seamlessly bridge PSR-7 and Yii2 request data, including support for uploaded files and CSRF token retrieval from headers.
  • Bug Fixes

    • Improved error messaging when the PSR-7 request adapter is not set.
  • Tests

    • Updated tests to validate new error messages and PSR-7 adapter handling.

@coderabbitai
Copy link

coderabbitai bot commented Jul 21, 2025

Walkthrough

A new enum case was added to the Message enum for standardized error messaging. The Request class was extensively updated to support PSR-7 ServerRequest interoperability, including adapter management, method overrides, and conversion utilities. Related tests were updated to use the new enum-based message.

Changes

File(s) Change Summary
src/exception/Message.php Added PSR7_REQUEST_ADAPTER_NOT_SET enum case for standardized error messages.
src/http/Request.php Major enhancements: PSR-7 ServerRequest adapter integration, new/overridden methods, conversion utilities.
tests/http/RequestTest.php Updated test to expect the new enum-based exception message and imported the Message class.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Request
    participant ServerRequestAdapter
    participant YiiRequest

    Client->>Request: setPsr7Request(ServerRequestInterface)
    Request->>ServerRequestAdapter: Store adapter

    Client->>Request: getBodyParams()/getHeaders()/etc.
    alt Adapter is set
        Request->>ServerRequestAdapter: Delegate method call
        ServerRequestAdapter-->>Request: Return PSR-7 data
    else Adapter not set
        Request->>YiiRequest: Call parent Yii2 method
        YiiRequest-->>Request: Return Yii2 data
    end

    Client->>Request: getPsr7Request()
    alt Adapter is set
        Request-->>Client: Return PSR-7 ServerRequest
    else Adapter not set
        Request-->>Client: Throw InvalidConfigException with Message::PSR7_REQUEST_ADAPTER_NOT_SET
    end
Loading

Estimated code review effort

4 (60–120 minutes)

Possibly related PRs

Suggested labels

bug

Poem

In a patch of code, a rabbit hops,
Adapters set, the switching never stops.
PSR-7 and Yii2 now dance in sync,
Enum messages help us catch the missing link.
With tests updated, all is right—
Hopping forward, code shines bright! 🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Jul 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ae94d3c) to head (e37dd32).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #19   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        99        99           
===========================================
  Files              6         6           
  Lines            252       252           
===========================================
  Hits             252       252           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@terabytesoftw terabytesoftw added the enhancement New feature or request label Jul 21, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/http/Request.php (1)

511-522: Consider null-safe handling for file size

The getSize() method on PSR-7 UploadedFileInterface can return null if the size is unknown. Consider adding a null-coalescing operator for consistency with other properties:

-                'size' => $psrFile->getSize(),
+                'size' => $psrFile->getSize() ?? 0,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ae94d3c and e37dd32.

📒 Files selected for processing (3)
  • src/exception/Message.php (1 hunks)
  • src/http/Request.php (13 hunks)
  • tests/http/RequestTest.php (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods, so individual test methods that extend TestCase don't need manual $_SERVER restoration.
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods (lines 28 and 32), so individual test methods that extend TestCase don't need manual $_SERVER restoration.
tests/http/RequestTest.php (3)

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods, so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods (lines 28 and 32), so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1564-1578
Timestamp: 2025-07-20T16:33:57.457Z
Learning: The TestCase class in yii2-extensions/psr-bridge automatically handles $_SERVER superglobal cleanup by saving its original state before each test and restoring it afterward in setUp() and tearDown() methods. Manual $_SERVER cleanup in individual test methods is unnecessary when extending this TestCase.

src/http/Request.php (3)

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods, so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.300Z
Learning: In the yii2-extensions/psr-bridge project, the base TestCase class already handles $_SERVER cleanup in setUp() and tearDown() methods (lines 28 and 32), so individual test methods that extend TestCase don't need manual $_SERVER restoration.

Learnt from: terabytesoftw
PR: #6
File: tests/http/RequestTest.php:1564-1578
Timestamp: 2025-07-20T16:33:57.457Z
Learning: The TestCase class in yii2-extensions/psr-bridge automatically handles $_SERVER superglobal cleanup by saving its original state before each test and restoring it afterward in setUp() and tearDown() methods. Manual $_SERVER cleanup in individual test methods is unnecessary when extending this TestCase.

🧬 Code Graph Analysis (2)
tests/http/RequestTest.php (1)
src/exception/Message.php (1)
  • getMessage (90-93)
src/http/Request.php (4)
src/adapter/ServerRequestAdapter.php (3)
  • ServerRequestAdapter (47-449)
  • getHeaders (141-150)
  • getQueryString (249-252)
src/exception/Message.php (1)
  • getMessage (90-93)
tests/provider/RequestProvider.php (1)
  • getQueryString (256-284)
tests/support/FactoryHelper.php (1)
  • createUploadedFile (181-189)
🔇 Additional comments (5)
src/exception/Message.php (1)

53-58: LGTM!

The new enum case follows the established pattern and provides a clear, standardized error message for PSR-7 adapter configuration issues.

tests/http/RequestTest.php (1)

12-12: Good consistency improvement!

The test now uses the standardized error message from the enum, which improves maintainability and consistency across the codebase.

Also applies to: 1524-1524

src/http/Request.php (3)

15-57: Excellent documentation enhancement!

The comprehensive class-level documentation clearly explains the PSR-7 bridge functionality, key features, and usage patterns. The property definitions are well-documented and appropriately scoped.


59-419: Comprehensive method documentation added!

The detailed documentation for all public methods provides excellent clarity on:

  • PSR-7 adapter behavior and fallback mechanisms
  • Exception handling
  • Return types and usage examples
  • Compatibility considerations

This significantly improves the developer experience.


251-258: Proper use of standardized error messaging!

The method correctly uses the new enum message for consistency and throws the appropriate exception when the adapter is not configured.

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants