Skip to content

Conversation

@terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Aug 10, 2025

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

Summary by CodeRabbit

  • Documentation

    • Improved and clarified documentation for request methods, including enhanced type annotations and usage examples.
  • Bug Fixes

    • Refined script URL handling in worker and traditional modes to better support PSR-7 and Yii2 environments, ensuring correct behavior when certain server parameters are missing.
  • Tests

    • Added new tests to verify script URL behavior under various adapter modes and server parameter scenarios.
    • Removed outdated tests related to script URL retrieval from the adapter test suite.

…dapter` class and related tests; introduce `getScriptName()` for improved script URL handling in PSR-7 and Yii2 environments.
@coderabbitai
Copy link

coderabbitai bot commented Aug 10, 2025

Walkthrough

The changes remove the getScriptUrl() method from the ServerRequestAdapter class and migrate its logic directly into the Request class, which now returns an empty string in worker mode with an adapter set or retrieves the script name otherwise. PHPDoc comments and PHPStan annotations are improved, and tests for getScriptUrl() are moved from the adapter test suite to the request test suite.

Changes

Cohort / File(s) Change Summary
Adapter Method Removal
src/adapter/ServerRequestAdapter.php
Deleted the getScriptUrl(bool $workerMode): string method and its docblock from the adapter class. No other logic was changed.
Request Logic & Docs Update
src/http/Request.php
Refactored getScriptUrl() to return empty string in worker mode with adapter set, otherwise retrieve script name via new private getScriptName() method or fallback to parent. Improved PHPDoc comments and PHPStan type annotations for multiple methods. Cached server parameters locally in getServerParam(). No other logic changes.
Test Additions (Request)
tests/adapter/ServerParamsPsr7Test.php
Added three new tests for Request::getScriptUrl() covering traditional mode with/without SCRIPT_NAME and worker mode scenarios. Each test verifies the returned script URL under various adapter and server parameter configurations.
Test Removals (Adapter)
tests/adapter/ServerRequestAdapterTest.php
Removed three tests that previously checked ServerRequestAdapter::getScriptUrl() behavior in similar scenarios; these tests are now redundant due to the logic migration to the Request class.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Request
    participant Adapter

    Client->>Request: getScriptUrl()
    alt Adapter is set and workerMode
        Request-->>Client: ""
    else Adapter is set and traditional mode
        Request->>Request: getScriptName()
        Request-->>Client: SCRIPT_NAME or ""
    else No adapter
        Request->>Request: parent::getScriptUrl()
        Request-->>Client: parent result
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A bunny hopped through code today,
Refactored script URLs the modern way.
With tests that leap from here to there,
And docs improved with extra care.
Adapter's burden now is light—
The Request class handles it just right!
🐇✨

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between f7d42df and 55730d0.

📒 Files selected for processing (1)
  • src/http/Request.php (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/http/Request.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix_mini_65

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.
  • 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.

Support

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

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 generate unit tests to generate unit tests for 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.

@terabytesoftw terabytesoftw added the bug Something isn't working label Aug 10, 2025
@codecov
Copy link

codecov bot commented Aug 10, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e0e6214) to head (f7d42df).

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #78   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
+ Complexity       313       311    -2     
===========================================
  Files             12        12           
  Lines            790       789    -1     
===========================================
- Hits             790       789    -1     

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

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: 3

🔭 Outside diff range comments (1)
src/http/Request.php (1)

515-539: getScriptUrl(): Logic LGTM; simplify control flow and fix misleading @throws

Behavior matches tests: empty string in worker mode when adapter is set; otherwise return SCRIPT_NAME; fallback to parent. Use a simple if for readability and remove @throws since nothing in this method throws.

-    /**
-     * Retrieves the script URL for the current request, supporting PSR-7 and Yii2 fallback.
-     *
-     * Returns the script URL as an empty string for PSR-7 worker environments (such as RoadRunner, FrankenPHP, etc.)
-     * where no script file exists, preventing URL duplication as routing is handled internally. If not in worker mode,
-     * return the script name. Falls back to the parent implementation if no PSR-7 adapter is set.
-     *
-     * This method enables seamless interoperability with both PSR-7 and Yii2 environments, ensuring the correct script
-     * URL resolution for modern HTTP stacks and legacy workflows.
-     *
-     * @throws InvalidConfigException if the configuration is invalid or incomplete.
-     *
-     * @return string Script URL for the current request, or an empty string in worker mode.
-     *
-     * Usage example:
-     * ```php
-     * $scriptUrl = $request->getScriptUrl();
-     * ```
-     */
+    /**
+     * Retrieves the script URL for the current request, supporting PSR-7 and Yii2 fallback.
+     *
+     * In worker environments (RoadRunner, FrankenPHP, etc.) with a PSR-7 adapter set, returns an empty string, since no
+     * script file exists and routing is handled by the worker. In traditional mode, returns 'SCRIPT_NAME'. Falls back
+     * to the parent implementation if no PSR-7 adapter is set.
+     *
+     * @return string Script URL for the current request, or an empty string in worker mode.
+     *
+     * Usage example:
+     * ```php
+     * $scriptUrl = $request->getScriptUrl();
+     * ```
+     */
     public function getScriptUrl(): string
     {
-        return match ($this->adapter !== null) {
-            true => $this->workerMode === true ? '' : $this->getScriptName(),
-            default => parent::getScriptUrl(),
-        };
+        if ($this->adapter !== null) {
+            return $this->workerMode ? '' : $this->getScriptName();
+        }
+        return parent::getScriptUrl();
     }
🧹 Nitpick comments (1)
src/http/Request.php (1)

590-593: Minor: avoid duplicate getServerParams() calls

Readability and micro-efficiency: call getServerParams() once.

-    public function getServerParam(string $name, mixed $default = null): mixed
-    {
-        return array_key_exists($name, $this->getServerParams()) ? $this->getServerParams()[$name] : $default;
-    }
+    public function getServerParam(string $name, mixed $default = null): mixed
+    {
+        $params = $this->getServerParams();
+        return array_key_exists($name, $params) ? $params[$name] : $default;
+    }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between e0e6214 and 025b3c3.

📒 Files selected for processing (4)
  • src/adapter/ServerRequestAdapter.php (0 hunks)
  • src/http/Request.php (8 hunks)
  • tests/adapter/ServerParamsPsr7Test.php (2 hunks)
  • tests/adapter/ServerRequestAdapterTest.php (0 hunks)
💤 Files with no reviewable changes (2)
  • src/adapter/ServerRequestAdapter.php
  • tests/adapter/ServerRequestAdapterTest.php
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
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.341Z
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.
📚 Learning: 2025-07-20T16:35:15.341Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
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.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-08-06T22:52:05.608Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#64
File: tests/http/StatelessApplicationTest.php:1939-1967
Timestamp: 2025-08-06T22:52:05.608Z
Learning: In yii2-extensions/psr-bridge tests, when testing specific component methods like Request::resolve(), it's necessary to call $app->handle($request) first to initialize all application components before testing the method in isolation. This ensures proper component lifecycle initialization.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
📚 Learning: 2025-07-20T16:35:15.341Z
Learnt from: terabytesoftw
PR: yii2-extensions/psr-bridge#6
File: tests/http/RequestTest.php:1536-1552
Timestamp: 2025-07-20T16:35:15.341Z
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.

Applied to files:

  • tests/adapter/ServerParamsPsr7Test.php
🪛 GitHub Actions: ecs
tests/adapter/ServerParamsPsr7Test.php

[error] 440-500: PHP CS Fixer detected an error in code style/order in this test file. The error is fixable by running the tool with the '--fix' option.

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
  • GitHub Check: mutation / PHP 8.3-ubuntu-latest
🔇 Additional comments (5)
tests/adapter/ServerParamsPsr7Test.php (1)

446-498: Drop unnecessary @throws annotations in tests
The @throws InvalidConfigException docblocks in these PHPUnit methods aren’t needed and can trigger ECS/CS ordering/style issues. Removing them keeps the tests focused and should resolve any style violations.

Please remove the docblocks in tests/adapter/ServerParamsPsr7Test.php around these methods and then verify compliance by running your project’s ECS or PHP CS Fixer:

--- a/tests/adapter/ServerParamsPsr7Test.php
+++ b/tests/adapter/ServerParamsPsr7Test.php
@@ -446,9 +446,6 @@ final class ServerParamsPsr7Test extends TestCase
-    /**
-     * @throws InvalidConfigException if the configuration is invalid or incomplete.
-     */
     public function testReturnEmptyScriptUrlWhenAdapterIsSetInTraditionalModeWithoutScriptName(): void
     {
         $request = new Request(['workerMode' => false]);
@@ -464,9 +461,6 @@ final class ServerParamsPsr7Test extends TestCase
-    /**
-     * @throws InvalidConfigException if the configuration is invalid or incomplete.
-     */
     public function testReturnEmptyScriptUrlWhenAdapterIsSetInWorkerMode(): void
     {
         $request = new Request();
@@ -482,9 +476,6 @@ final class ServerParamsPsr7Test extends TestCase
-    /**
-     * @throws InvalidConfigException if the configuration is invalid or incomplete.
-     */
     public function testReturnScriptNameWhenAdapterIsSetInTraditionalMode(): void
     {
         $expectedScriptName = '/app/public/index.php';

Run your style checker locally to confirm no remaining violations.

src/http/Request.php (4)

823-839: New helper getScriptName(): clear and correct

Straightforward, type-safe retrieval of SCRIPT_NAME. No issues.


158-159: Doc type refinement for getBodyParams()

Type expansion to array|object is appropriate given PSR-7 parsed body possibilities.


320-321: Doc type refinement for getParsedBody()

Allowing object|null matches PSR-7's getParsedBody() contract. LGTM.


533-539: All ServerRequestAdapter::getScriptUrl() references have been removed

Ripgrep searches confirm there’s no getScriptUrl() declaration in ServerRequestAdapter and no calls to adapter->getScriptUrl(). No further action required.

…notation for clarity; add tests for script URL handling in traditional and worker modes in `ServerParamsPsr7Test`.
…oadedFiles()` and `convertPsr7ToUploadedFiles()` methods for improved type clarity.
@terabytesoftw terabytesoftw merged commit 7ce190a into main Aug 10, 2025
27 checks passed
@terabytesoftw terabytesoftw deleted the fix_mini_65 branch August 10, 2025 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants