Issue/534 http client curl adapters#562
Conversation
📝 WalkthroughWalkthroughChangesHttpClient adapter refactor
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant HttpClient
participant CurlAdapter
participant MultiCurlAdapter
participant php-curl-class
HttpClient->>CurlAdapter: create and configure single request
CurlAdapter->>php-curl-class: forward request operations
php-curl-class-->>CurlAdapter: return execution and response data
HttpClient->>MultiCurlAdapter: queue requests and register callbacks
MultiCurlAdapter->>php-curl-class: start multi request
php-curl-class-->>MultiCurlAdapter: invoke callback with Curl
MultiCurlAdapter-->>HttpClient: provide CurlAdapter callback argument
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 37fc64831f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (1)
src/HttpClient/HttpClient.php (1)
326-336: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRemove redundant
ensureRequestCreated()call.
ensureRequestCreated()is already invoked at the start of the__callmethod. SinceinterceptCall()operates on header arrays and does not unset or modify$this->client, callingensureRequestCreated()a second time is unnecessary.♻️ Proposed fix
$this->interceptCall($method, $arguments); - $this->ensureRequestCreated(); - $this->client->callMethod($method, $arguments);🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/HttpClient/HttpClient.php` around lines 326 - 336, Remove the second redundant ensureRequestCreated() call in __call after interceptCall(), preserving the initial request creation check and the existing supportsMethod, interceptCall, and callMethod flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/HttpClient/Adapters/CurlAdapter.php`:
- Around line 143-146: Update the option dispatch in getInfo to use a strict
null check instead of truthiness, ensuring option value 0 is passed to
client->getInfo($option) while null continues calling client->getInfo() without
arguments.
In `@src/HttpClient/Adapters/MultiCurlAdapter.php`:
- Around line 39-51: Update MultiCurlAdapter::success and
MultiCurlAdapter::error to register closures that wrap each raw vendor Curl
instance in CurlAdapter before invoking the user callback, matching complete().
In tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php lines 43-56, update
mock expectations for closure registration and assert callbacks receive
CurlAdapter instances.
- Around line 61-77: The addGet and addPost methods in
src/HttpClient/Adapters/MultiCurlAdapter.php#L61-L77 must prevent raw vendor
Curl instances from crossing the adapter boundary: capture each vendor result
and wrap it in CurlAdapter when it is a Curl object, otherwise preserve the
existing return behavior. Update
src/HttpClient/Adapters/MultiCurlAdapter.php#L61-L77 accordingly. In
src/HttpClient/Adapters/MultiCurlAdapterTest.php#L28-L39, return
Mockery::mock(Curl::class) from the mocks and assert both addGet and addPost
return CurlAdapter instances.
In `@src/HttpClient/HttpClient.php`:
- Around line 394-401: Update ensureSingleRequest() to call
ensureRequestCreated() before checking isMultiRequest(). Preserve the existing
MultiCurlAdapter rejection and exception behavior, while ensuring the method’s
CurlAdapterInterface assertion only applies after a client has been created.
- Around line 178-183: Update the `@phpstan-assert-if-false` annotation on
isMultiRequest() to declare that a false result leaves $this->client as
CurlAdapterInterface|null, while preserving the existing true assertion and
method behavior.
- Around line 274-293: Update getResponse() and getErrors() to return an empty
array when $this->client is null, before the fallback calls
$this->client->getId(). Preserve the existing multi-request and
initialized-client behavior.
---
Nitpick comments:
In `@src/HttpClient/HttpClient.php`:
- Around line 326-336: Remove the second redundant ensureRequestCreated() call
in __call after interceptCall(), preserving the initial request creation check
and the existing supportsMethod, interceptCall, and callMethod flow.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: dd453cd6-d26b-4200-bdaa-bf178403a7d6
📒 Files selected for processing (12)
CHANGELOG.mdsrc/HttpClient/Adapters/CurlAdapter.phpsrc/HttpClient/Adapters/MultiCurlAdapter.phpsrc/HttpClient/Contracts/CurlAdapterInterface.phpsrc/HttpClient/Contracts/HttpClientAdapterInterface.phpsrc/HttpClient/Contracts/MultiCurlAdapterInterface.phpsrc/HttpClient/Enums/HttpClientType.phpsrc/HttpClient/Factories/HttpClientFactory.phpsrc/HttpClient/HttpClient.phptests/Unit/HttpClient/Adapters/CurlAdapterTest.phptests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.phptests/Unit/HttpClient/HttpClientTest.php
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php`:
- Around line 32-39: Update testHttpClientFactoryResolveReturnsSameInstance to
obtain one client through HttpClientFactory::get() and the other through
Di::get(HttpClientFactory::class)->resolve(), then assert they are the same
instance. Ensure the test covers identity across both factory entry points
rather than only repeated resolve() calls.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 5e09ca8f-d418-481a-bde5-b52e091c1102
📒 Files selected for processing (7)
src/HttpClient/Adapters/CurlAdapter.phpsrc/HttpClient/Adapters/MultiCurlAdapter.phpsrc/HttpClient/HttpClient.phptests/Unit/HttpClient/Adapters/CurlAdapterTest.phptests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.phptests/Unit/HttpClient/Factories/HttpClientFactoryTest.phptests/Unit/HttpClient/HttpClientTest.php
🚧 Files skipped from review as they are similar to previous changes (4)
- src/HttpClient/Adapters/CurlAdapter.php
- tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
- tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
- src/HttpClient/Adapters/MultiCurlAdapter.php
Closes #534
This PR separates
HttpClientexecution behind Quantum-ownedCurlAdapterandMultiCurlAdapterwrappers while preserving the existingHttpClientfacade and keepingphp-curl-classunderneath for this phase.It does not remove
php-curl-classyet. That is intentionally deferred so native curl replacement can be implemented and reviewed separately against the adapter contracts introduced here.Retiring
php-curl-class/php-curl-classwill be handled in follow-up ticket(s).Summary by CodeRabbit
info(0)calls (now verified by tests).