Opened 3 months ago
Closed 3 months ago
#65916 closed defect (bug) (fixed)
Docs: WP_Image_Editor_Imagick::remove_pdf_alpha_channel() is missing an @return tag
| Reported by: | mazharul78 | Owned by: | jorbin |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2 |
| Component: | Media | Version: | 6.4 |
| Severity: | trivial | Keywords: | has-patch |
| Cc: | Focuses: | docs |
Description
WP_Image_Editor_Imagick::remove_pdf_alpha_channel() returns a WP_Error if Imagick::setImageAlphaChannel() throws, but there's no @return tag in the DocBlock. It's been like that since the method was added in [56271] (#39216).
/** * Removes PDF alpha after it's been read. * * @since 6.4.0 */ protected function remove_pdf_alpha_channel() { ... } catch ( Exception $e ) { return new WP_Error( 'pdf_alpha_process_failed', $e->getMessage() ); }
I noticed it while looking at #65817. PHPStan's return.missing rule didn't flag it because there's no declared return type, so it got skipped even though set_imagick_time_limit() in the same file is being fixed for that rule.
PR just adds the tag, nothing else changes. 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 from load() would kill the PDF preview completely instead of just giving you one with a black background, which seems worse. Or the WP_Error could just come out since nothing reads it. Left it alone for now, can do either if someone has a preference.
PR: https://github.com/WordPress/wordpress-develop/pull/13200
## Problem
WP_Image_Editor_Imagick::remove_pdf_alpha_channel()was introduced in [56271] (#39216, WordPress 6.4). It returns aWP_Errorobject whenImagick::setImageAlphaChannel()throws:Its DocBlock declares no return value at all:
## Why this was not caught by the existing sweeps
PHPStan's
return.missingrule only fires when a return type is declared. Because this method declares none, it stayed silent — while its siblingset_imagick_time_limit(), in this same file, is being fixed for that exact rule in #13082 (Trac #65817).## This PR
Documents the existing return value. No behavior change, no new PHPCS errors (
WordPress-Docscommenting sniffs report the same 13 pre-existing errors in this file before and after).## Open question for a committer
The sole caller discards the return value:
https://github.com/WordPress/wordpress-develop/blob/trunk/src/wp-includes/class-wp-image-editor-imagick.php#L371-L373
...even though the adjacent
pdf_load_source()and->valid()results are both error-checked. Two possible follow-ups, both behavior-affecting and deliberately left out of this PR:load()— but a failed alpha strip would then abort PDF preview generation entirely, rather than yielding a preview with a black background. That may be worse for users.WP_Errorreturn as dead code.Happy to follow up with whichever is preferred.