Skip to content

Issue/563 http client request factory#564

Merged
armanist merged 5 commits into
quantum-php:masterfrom
armanist:issue/563-http-client-request-factory
Jul 18, 2026
Merged

Issue/563 http client request factory#564
armanist merged 5 commits into
quantum-php:masterfrom
armanist:issue/563-http-client-request-factory

Conversation

@armanist

@armanist armanist commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Closes #563

Summary by CodeRabbit

  • New Features

    • Added convenient helper functions for creating single, multi-request, and asynchronous multi-request HTTP clients.
    • HTTP client creation now provides a fresh client for each request type.
  • Improvements

    • Standardized request startup methods to complete without returning execution results.
    • Added clearer type declarations for HTTP client operations.
  • Removed

    • Removed the previous shared-instance factory behavior and legacy client type constants.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

HTTP client adapter start() methods now return void. The cached factory was replaced with fresh static request creators, global helper functions were added, HttpClientType was removed, and unit tests now cover adapter delegation plus factory/helper-created clients.

Changes

HTTP client lifecycle and creation

Layer / File(s) Summary
Void adapter lifecycle
src/HttpClient/Contracts/HttpClientAdapterInterface.php, src/HttpClient/Adapters/*, tests/Unit/HttpClient/Adapters/*
Adapter start() methods now declare void and only perform their underlying execution side effect; tests no longer assert return values.
Fresh factory and helper creation
src/HttpClient/Factories/HttpClientFactory.php, src/HttpClient/Helpers/http_client.php, src/HttpClient/Enums/HttpClientType.php
The cached DI-backed factory was replaced with static creators for single, multi, and asynchronous multi requests; matching global helpers were added and HttpClientType was removed.
Factory and helper validation
tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php, tests/Unit/HttpClient/Helpers/HttpClientHelperFunctionsTest.php
Tests verify client types, adapter selection, multi-request configuration, callbacks, and distinct instances across factory and helper calls.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant HttpClientFactory
  participant HttpClient
  Caller->>HttpClientFactory: createRequest or createMultiRequest
  HttpClientFactory->>HttpClient: create fresh configured client
  HttpClientFactory-->>Caller: return HttpClient
Loading

Possibly related PRs

Suggested labels: http, refactoring

Suggested reviewers: andrey-smaelov

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning Fresh factory/helper APIs and void start contracts are added, but required core package integration and documentation updates aren't shown. Add the missing core package usage updates (Captcha, Lang, Storage, Mailer) and document the new helper/factory usage, while keeping backward-compatible create*Request methods.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and matches the main change: refactoring the HttpClient request factory API.
Out of Scope Changes check ✅ Passed The changes stay within the HttpClient factory/helper refactor, tests, enum removal, and adapter contract alignment.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

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

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/HttpClient/Helpers/http_client.php (1)

12-34: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Wrap global helper functions with function_exists.

It is highly recommended to wrap global helper function declarations in if (!function_exists(...)) checks. This defensive programming practice prevents fatal redeclaration errors if the file is ever loaded multiple times by the autoloader or manual includes.

♻️ Proposed refactor
-/**
- * Creates single HTTP request client
- */
-function httpRequest(string $url): HttpClient
-{
-    return HttpClientFactory::createRequest($url);
-}
-
-/**
- * Creates multi HTTP request client
- */
-function httpMultiRequest(): HttpClient
-{
-    return HttpClientFactory::createMultiRequest();
-}
-
-/**
- * Creates async multi HTTP request client
- */
-function httpAsyncMultiRequest(callable $success, callable $error): HttpClient
-{
-    return HttpClientFactory::createAsyncMultiRequest($success, $error);
-}
+if (!function_exists('httpRequest')) {
+    /**
+     * Creates single HTTP request client
+     */
+    function httpRequest(string $url): HttpClient
+    {
+        return HttpClientFactory::createRequest($url);
+    }
+}
+
+if (!function_exists('httpMultiRequest')) {
+    /**
+     * Creates multi HTTP request client
+     */
+    function httpMultiRequest(): HttpClient
+    {
+        return HttpClientFactory::createMultiRequest();
+    }
+}
+
+if (!function_exists('httpAsyncMultiRequest')) {
+    /**
+     * Creates async multi HTTP request client
+     */
+    function httpAsyncMultiRequest(callable $success, callable $error): HttpClient
+    {
+        return HttpClientFactory::createAsyncMultiRequest($success, $error);
+    }
+}
🤖 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/Helpers/http_client.php` around lines 12 - 34, Wrap each
global helper declaration—httpRequest, httpMultiRequest, and
httpAsyncMultiRequest—in function_exists guards so they are defined only when
not already declared, while preserving their existing signatures and delegation
to HttpClientFactory.
tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php (1)

13-21: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Assert that the URL is correctly wired into the client.

While the tests successfully verify that a fresh HttpClient instance backed by a CurlAdapter is returned, they do not assert that the $url argument was properly passed down to the client configuration. Adding these assertions will improve confidence in the parameter wiring.

  • tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php#L13-L21: Add $this->assertSame('https://example.com', $httpClient1->url()); (and similarly for $httpClient2) to verify the URL was set.
  • tests/Unit/HttpClient/Helpers/HttpClientHelperFunctionsTest.php#L12-L20: Add the same assertions here to ensure the helper perfectly forwards the URL.
🤖 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 `@tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php` around lines 13 -
21, Update testHttpClientFactoryCreatesSingleRequest in
tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php at lines 13-21 to
assert each returned client's url() matches its input URL; add equivalent URL
assertions in tests/Unit/HttpClient/Helpers/HttpClientHelperFunctionsTest.php at
lines 12-20 to verify helper forwarding.
🤖 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.

Nitpick comments:
In `@src/HttpClient/Helpers/http_client.php`:
- Around line 12-34: Wrap each global helper declaration—httpRequest,
httpMultiRequest, and httpAsyncMultiRequest—in function_exists guards so they
are defined only when not already declared, while preserving their existing
signatures and delegation to HttpClientFactory.

In `@tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php`:
- Around line 13-21: Update testHttpClientFactoryCreatesSingleRequest in
tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php at lines 13-21 to
assert each returned client's url() matches its input URL; add equivalent URL
assertions in tests/Unit/HttpClient/Helpers/HttpClientHelperFunctionsTest.php at
lines 12-20 to verify helper forwarding.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 466a060b-5de7-465b-acb7-af8fc48123d2

📥 Commits

Reviewing files that changed from the base of the PR and between af03b2e and 34b554c.

📒 Files selected for processing (10)
  • src/HttpClient/Adapters/CurlAdapter.php
  • src/HttpClient/Adapters/MultiCurlAdapter.php
  • src/HttpClient/Contracts/HttpClientAdapterInterface.php
  • src/HttpClient/Enums/HttpClientType.php
  • src/HttpClient/Factories/HttpClientFactory.php
  • src/HttpClient/Helpers/http_client.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
  • tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php
  • tests/Unit/HttpClient/Helpers/HttpClientHelperFunctionsTest.php
💤 Files with no reviewable changes (1)
  • src/HttpClient/Enums/HttpClientType.php

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34b554c60c

ℹ️ 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".

Comment thread src/HttpClient/Factories/HttpClientFactory.php
@armanist
armanist merged commit c0aa53b into quantum-php:master Jul 18, 2026
6 checks passed
@armanist
armanist deleted the issue/563-http-client-request-factory branch July 18, 2026 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refine HttpClient factory lifecycle and request helper API after #534

3 participants