Skip to content

Migrate Adapter::call() to utopia-php/fetch#63

Open
lohanidamodar wants to merge 3 commits intomainfrom
feat/clo-4290-migrate-to-fetch
Open

Migrate Adapter::call() to utopia-php/fetch#63
lohanidamodar wants to merge 3 commits intomainfrom
feat/clo-4290-migrate-to-fetch

Conversation

@lohanidamodar
Copy link
Copy Markdown
Contributor

@lohanidamodar lohanidamodar commented May 3, 2026

Summary

  • Replace raw PHP curl in Analytics\Adapter::call() with utopia-php/fetch (^1.1).
  • Response headers now read from Response::getHeaders() instead of a CURLOPT_HEADERFUNCTION callback.
  • Adapter public API unchanged.

Why

  • Unifies HTTP handling across the Utopia ecosystem.
  • Removes the PHP 8.5 curl_close() deprecation as a side effect.

Notable behavior fix (in follow-up commit)

The original code in Adapter::call() looked up the response content-type with $responseHeaders['Content-Type'], but the legacy CURLOPT_HEADERFUNCTION callback already lowercased every header key — so the capitalized lookup never matched and the JSON-decode branch was dead code. utopia-php/fetch also returns lowercase keys, so the migration didn't introduce the bug, but it's the right place to fix it. The follow-up commit:

  • Switches the lookup to 'content-type'.
  • Fixes a related bug where substr(..., 0, strpos(..., ';')) returned '' for content-types without a ; (so even with the right key case, plain application/json would have missed).
  • Removes the now-redundant json_decode($x, true) calls in 4 concrete adapters (GoogleAnalytics, HubSpot, Orbit, Plausible) that compensated for the dead branch — without that change they'd start double-decoding.
  • Preserves FetchException::getCode() when re-throwing as a plain Exception (Greptile P2).

Test plan

  • composer lint (Pint)
  • php -l on every modified file
  • composer test — same pre-existing failure pattern as main (expired test API keys for Plausible/Orbit/HubSpot/Mixpanel/ReoDev). No regression introduced.

Lint cleanup commit

Pre-existing Pint violations in Adapter/Mixpanel.php and tests/Analytics/AnalyticsTest.php were blocking CI on this PR. Auto-fixed via composer format. These files are not part of the migration scope but the linter needs to pass for the PR to merge cleanly.

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 3, 2026

Greptile Summary

This PR replaces raw PHP curl in Adapter::call() with utopia-php/fetch, removes the PHP 8.5 curl_close() deprecation, and fixes two long-standing bugs: the Content-Type response header was previously looked up with the wrong case ('Content-Type' instead of 'content-type'), silently making the JSON-decode branch dead code, and the substr/strpos pattern for stripping charset suffixes failed on content-types without a ;. The follow-up commits correctly remove the compensating json_decode calls in all four concrete adapters and preserve the FetchException code when re-throwing.

Confidence Score: 5/5

Safe to merge — all previously identified P1/P2 issues are addressed and no new defects were found.

Both previously flagged bugs (lowercase content-type key lookup and silent exception-code loss) are resolved. The adapter API is unchanged, the redundant json_decode calls in all four concrete adapters have been removed to prevent double-decoding, and the minimum PHP version bump to 8.1 is correctly reflected in both composer.json and composer.lock. No P0 or P1 issues remain.

No files require special attention.

Important Files Changed

Filename Overview
src/Analytics/Adapter.php Core migration from raw curl to utopia-php/fetch; both previously-identified bugs (lowercase content-type key, FetchException code preservation) are now fixed.
src/Analytics/Adapter/GoogleAnalytics.php Removed now-redundant json_decode calls; call() already returns a decoded array for application/json responses.
src/Analytics/Adapter/HubSpot.php Removed three redundant json_decode calls; no logic changes, behavior is identical with the fixed call() method.
src/Analytics/Adapter/Orbit.php Removed two redundant json_decode calls; responses are now pre-decoded by call().
src/Analytics/Adapter/Plausible.php Removed one redundant json_decode call; no logic changes.
composer.json Added utopia-php/fetch ^1.1 dependency and raised minimum PHP version from 8.0 to 8.1 (required by the new library).
composer.lock Lock file updated to include utopia-php/fetch 1.1.2 and reflect bumped dev-dependency versions.
tests/Analytics/AnalyticsTest.php Replaced FQCNs in @var docblocks with short imported class names; no behaviour change.

Reviews (2): Last reviewed commit: "Apply Pint to Mixpanel.php and Analytics..." | Re-trigger Greptile

Comment thread src/Analytics/Adapter.php Outdated
Comment thread src/Analytics/Adapter.php
Addresses Greptile review feedback on the utopia-php/fetch migration. The original code looked up the response Content-Type header with a capitalized key while utopia-php/fetch lowercases all keys, so the JSON decode branch never fired. Concrete adapters compensated with their own json_decode() calls; with the lookup fixed, those become redundant and are removed.
Pre-existing style violations (fully_qualified_strict_types, unary_operator_spaces) were blocking CI on the migration PR. Auto-fixed via composer format.
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.

2 participants