Docs: Add missing @return tag to WP_Image_Editor_Imagick::remove_pdf_alpha_channel() - #13200
Docs: Add missing @return tag to WP_Image_Editor_Imagick::remove_pdf_alpha_channel()#13200csemazharul wants to merge 4 commits into
@return tag to WP_Image_Editor_Imagick::remove_pdf_alpha_channel()#13200Conversation
`WP_Image_Editor_Imagick::remove_pdf_alpha_channel()`, introduced in [56271], returns a `WP_Error` object when `Imagick::setImageAlphaChannel()` throws, but its DocBlock declares no return value. This documents the existing return value only; no behavior is changed. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| * | ||
| * @since 6.4.0 | ||
| * | ||
| * @return void|WP_Error WP_Error object if the alpha channel could not be removed. |
There was a problem hiding this comment.
I'm going to change this to null|WP_Error for the reasons in Core-64694.
…` return type. `void` cannot be a member of a union type: it means the function returns no value, which contradicts the `WP_Error` half of the annotation. Core has been systematically removing this construct — see r61716, r61719, r62178 and r62179, the latter two of which also add explicit `return null;` statements where functions previously fell through without a return value. After those sweeps only one `X|void` annotation remained in `src/`. The distinction is not cosmetic here. PHPStan normalizes `void|WP_Error` to `WP_Error|null` and skips the check, so at level 10 the method reports no errors. Spelled `null|WP_Error` it correctly reports `return.missing`, since the method falls off the end without returning. The `void` spelling documents the return value while suppressing the very rule that would enforce it, which is at odds with the change being made for static analysis in the first place. Order the union as `null|WP_Error` and describe it as "Null on success" to match the closest analogues in core, `activate_plugin()` and `WP_REST_Meta_Fields::update_value()`. Add the explicit `return null;`, the same shape applied to `wp_dashboard_quota()` in r62179. The only caller, in `load()`, still discards the return value. That is deliberate: surfacing the error would fail the PDF preview outright rather than degrade it to a black background, and r56271 clearly intended the alpha removal to be best-effort. No behavior changes here — the method already returned `null` implicitly. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Document `WP_Image_Editor_Imagick::remove_pdf_alpha_channel()` as returning `null|WP_Error` and explicitly return null on success. Developed in: #13200 Follow-up to r56271. Props mazharul78, westonruter. Fixes #65916. See #39216, #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@63369 602fd350-edb4-49c9-b593-d223f7449a82
Document `WP_Image_Editor_Imagick::remove_pdf_alpha_channel()` as returning `null|WP_Error` and explicitly return null on success. Developed in: WordPress/wordpress-develop#13200 Follow-up to r56271. Props mazharul78, westonruter. Fixes #65916. See #39216, #65817. Built from https://develop.svn.wordpress.org/trunk@63369 git-svn-id: http://core.svn.wordpress.org/trunk@62562 1a063a9b-81f0-0310-95a4-ce76da25c4cd
Trac ticket: https://core.trac.wordpress.org/ticket/65916
WP_Image_Editor_Imagick::remove_pdf_alpha_channel()returns aWP_ErrorifImagick::setImageAlphaChannel()throws, but there's no@returntag in the DocBlock. Been like that since the method was added in changeset 56271 (Trac #39216).Found it while looking at Trac #65817. PHPStan's
return.missingrule didn't catch it because there's no declared return type, so it got skipped even thoughset_imagick_time_limit()in the same file is being fixed for that rule in #13082.This just adds the tag. Nothing else changes, and PHPCS output for the file is the same before and after.
One other thing I ran into: the only caller, on line 372, throws the return value away, while
pdf_load_source()and->valid()right next to it are both checked. Not sure what the right call is there. Returning the error fromload()would kill the PDF preview completely instead of just giving you one with a black background, which seems worse. Or theWP_Errorcould come out since nothing reads it. Left it alone for now, can do either if someone has a preference.Drafted Commit Message