Skip to content

Extract duplicated response-status validation into a shared helper #482

Description

@Art4

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).

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions