Problem
The response-status validation pattern (getContent() → getStatusCode() → compare → return body or throw UnexpectedResponseException based on Future::isForwardCompatibilityEnabled()) is copy-pasted across ~34 mutation methods in multiple Api classes.
This duplication already caused a bug in #465 where Issue::create(), IssueCategory::create(), and Membership::create() used a subtly different condition (&& $body === '') compared to every other method, breaking the BC guarantee for non-empty error responses.
A shared helper would make such drift structurally impossible.
Proposed Solution
Add a protected helper method (e.g. returnBodyOrThrow(array $expectedStatusCodes): string) on an appropriate base class, and replace all 34 inline blocks with calls to it.
However, AbstractApi is might be proposed for removal in the next major version. Therefore, the helper should be placed in a new trait or a separate base class that survives the deprecation timeline.
Affected Files
All src/Redmine/Api/*.php files with mutation methods (create/update/remove/addUser/removeUser/addWatcher/removeWatcher/upload/attachMany).
Problem
The response-status validation pattern (
getContent()→getStatusCode()→ compare → return body or throwUnexpectedResponseExceptionbased onFuture::isForwardCompatibilityEnabled()) is copy-pasted across ~34 mutation methods in multipleApiclasses.This duplication already caused a bug in #465 where
Issue::create(),IssueCategory::create(), andMembership::create()used a subtly different condition (&& $body === '') compared to every other method, breaking the BC guarantee for non-empty error responses.A shared helper would make such drift structurally impossible.
Proposed Solution
Add a protected helper method (e.g.
returnBodyOrThrow(array $expectedStatusCodes): string) on an appropriate base class, and replace all 34 inline blocks with calls to it.However,
AbstractApiis might be proposed for removal in the next major version. Therefore, the helper should be placed in a new trait or a separate base class that survives the deprecation timeline.Affected Files
All
src/Redmine/Api/*.phpfiles with mutation methods (create/update/remove/addUser/removeUser/addWatcher/removeWatcher/upload/attachMany).