fix: mpdf psr-http-message-shim v2 compatibility#782
Conversation
…bility The plugin-check WordPress plugin bundles psr/http-message v2.0 which adds return type declarations to all interface methods. When loaded before mpdf, PHP fatals because the shim classes implement the v2 interface without matching return types. The previous patch only covered Request.php. This extends it to all four shim files (Request, Response, Stream, Uri) with proper return types, parameter type hints, and bare return fixes for nullable returns. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThis patch adds strict PHP type declarations to PSR HTTP message shim classes (Request, Response, Stream, Uri). All public methods now have explicit return types and typed parameters for PHP 8+ compatibility, with the same functional behavior preserved. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
🔨 Build Complete - Ready for Testing!📦 Download Build Artifact (Recommended)Download the zip build, upload to WordPress and test:
🌐 Test in WordPress Playground (Very Experimental)Click the link below to instantly test this PR in your browser - no installation needed! Login credentials: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
patches/mpdf-psr-http-message-shim-php8-compat.patch (1)
1-503: Please add an autoload-order regression for this patch.This failure mode only appears when the PSR v2 interfaces are loaded before the shim, so a small integration check around that ordering would make this fix much harder to regress on the next vendor update.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@patches/mpdf-psr-http-message-shim-php8-compat.patch` around lines 1 - 503, Add an autoload-order regression test that reproduces the failure when PSR v2 interfaces are loaded before the shim: write an integration test that first ensures the PSR interfaces (e.g. \Psr\Http\Message\RequestInterface, \Psr\Http\Message\ResponseInterface, \Psr\Http\Message\StreamInterface, \Psr\Http\Message\UriInterface) are present/loaded, then require the shim (the patched classes Request, Response, Stream, Uri) and assert the shim classes correctly implement those interfaces and expose the fixed signatures by instantiating Request/Response/Stream/Uri and checking key behaviors (e.g. Request implements RequestInterface and getMethod() returns a string, Response implements ResponseInterface and getStatusCode() returns an int, Stream::getSize() returns ?int, Uri::getPort() returns ?int); fail the test if any implementation or return-type behavior differs to prevent regressions when autoload order changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@patches/mpdf-psr-http-message-shim-php8-compat.patch`:
- Around line 1-503: Add an autoload-order regression test that reproduces the
failure when PSR v2 interfaces are loaded before the shim: write an integration
test that first ensures the PSR interfaces (e.g.
\Psr\Http\Message\RequestInterface, \Psr\Http\Message\ResponseInterface,
\Psr\Http\Message\StreamInterface, \Psr\Http\Message\UriInterface) are
present/loaded, then require the shim (the patched classes Request, Response,
Stream, Uri) and assert the shim classes correctly implement those interfaces
and expose the fixed signatures by instantiating Request/Response/Stream/Uri and
checking key behaviors (e.g. Request implements RequestInterface and getMethod()
returns a string, Response implements ResponseInterface and getStatusCode()
returns an int, Stream::getSize() returns ?int, Uri::getPort() returns ?int);
fail the test if any implementation or return-type behavior differs to prevent
regressions when autoload order changes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d39a4f72-0079-4ce1-bfb9-d66942a0b226
📒 Files selected for processing (1)
patches/mpdf-psr-http-message-shim-php8-compat.patch
Summary
Root causeThe Test plan
Merged via PR #782 to main. aidevops.sh v3.6.235 spent 6m on this as a headless bash routine. |
|
Performance Test Results Performance test results for 5758967 are in 🛎️! Note: the numbers in parentheses show the difference to the previous (baseline) test run. Differences below 2% or 0.5 in absolute values are not shown. URL:
|
Summary
plugin-check(or any plugin bundlingpsr/http-messagev2) loads before mpdf's shim classesmpdf-psr-http-message-shim-php8-compat.patchto cover all 4 shim files (Request, Response, Stream, Uri) — previously only Request.php was patchedreturn;statements for nullable return typesa/src/...instead ofa/vendor/...) socweagans/composer-patchesapplies them correctlyRoot cause
The
plugin-checkWordPress plugin bundlespsr/http-messagev2.0 which declares return types on all interface methods (e.g.getRequestTarget(): string). When its autoloader loads the v2 interface before mpdf, the shim classes fail with:Test plan
composer installon a clean vendor — verify patch applies without errorsplugin-checkalongside Ultimate Multisite — verify no PHP fatal🤖 Generated with Claude Code
Summary by CodeRabbit