Skip to content

refactor(HTTP): split setCURLOptions into category helper methods to reduce complexity#10339

Open
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:refactor/setcurloptions
Open

refactor(HTTP): split setCURLOptions into category helper methods to reduce complexity#10339
gr8man wants to merge 2 commits into
codeigniter4:developfrom
gr8man:refactor/setcurloptions

Conversation

@gr8man

@gr8man gr8man commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Description

This PR refactors the massive setCURLOptions() method in CodeIgniter\HTTP\CURLRequest (which was a 180+ line method with extremely high cyclomatic complexity) by splitting it into 8 domain-specific private helper methods. This change adheres to the Single Responsibility Principle (SRP) and the Open-Closed Principle (OCP), making the options-building logic significantly cleaner, easier to read, and simpler to maintain without introducing any backward compatibility (BC) breaks.
Additionally, static analysis (PHPStan Level 6 with strict rules) and test validation have been integrated for all newly created helper methods.

Proposed Changes

  • system/HTTP/CURLRequest.php:
    • Extracted configuration building logic from setCURLOptions() into:
      • applyAuthOptions()
      • applySslOptions()
      • applyProxyOptions()
      • applyDebugOptions()
      • applyRedirectOptions()
      • applyConnectionOptions()
      • applyPayloadOptions()
      • applyMiscOptions()
    • Replaced legacy empty() checks with strict comparison operators (isset(), !== '', etc.) inside the new helper methods to comply with strict PHPStan rules.
    • Added full PHPDoc type annotations for arrays (solving missingType.iterableValue warnings).
  • tests/system/HTTP/CURLRequestTest.php:
    • Added direct reflection-based unit tests (testApply*Direct) using getPrivateMethodInvoker for all 8 helper methods to ensure maximum test coverage.
    • Adjusted float assertions from assertSame to assertEqualsWithDelta to satisfy Rector rules.
  • utils/phpstan-baseline/empty.notAllowed.neon:
    • Updated the baseline count for allowed empty() constructs for CURLRequest to match the new strict refactoring.

Checklist

  • All unit tests pass successfully (OK (100 tests, 269 assertions)).
  • PHPStan analysis passes with no errors ([OK] No errors).
  • Rector analysis passes with no errors.
  • Code formatting conforms to project standards (php-cs-fixer).
  • No changelog entry added (refactoring only, as there are no real changes for end users).

@gr8man gr8man force-pushed the refactor/setcurloptions branch from 0ea2fd3 to 2c5d21c Compare June 24, 2026 19: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.

1 participant