Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create factory methods in all API classes #368

Open
Art4 opened this issue Jan 24, 2024 · 0 comments
Open

Create factory methods in all API classes #368

Art4 opened this issue Jan 24, 2024 · 0 comments
Milestone

Comments

@Art4
Copy link
Collaborator

Art4 commented Jan 24, 2024

Declaring the classes in the Redmine\Api\ namespace as final will allow us to make more future changes without worrying to much about BC.

To achieve this in a FC way we could create new factory methods create(HttpClient $client): self in all API child classes.

class ProjectApi extends AbstractApi
{
    final public static function create(HttpClient $client): self
    {
        return new self($client);
    }

    /**
     * @param Client|HttpClient $client
     */
    final public function __construct($client)
    {
        if (get_called_class() !== __CLASS__) {
            @trigger_error('Extending ' . __CLASS__ . ' is deprecated since v2.x, it will become final in v3.0.0.');
        }

        if ($client instanceof Client) {
            $this->client = $client;
        }

        // Handle HttpClient...
    }
}

Using the HttpClient in the API classes makes the AbstractApi obsolete and can be deprecated. Extending it should also trigger a deprecation.

abstract class AbstractApi 
{
    /**
     * @param Client|HttpClient $client
     */
    public function __construct($client)
    {
        @trigger_error(__CLASS__ . ' is deprecated since v2.x and will be removed in v3.0.0.');

        // old code...
    }
}

Affected classes

  1. Redmine\Api\Attachment
  2. Redmine\Api\CustomField
  3. Redmine\Api\Group
  4. Redmine\Api\Issue
  5. Redmine\Api\IssueCategory
  6. Redmine\Api\IssuePriority
  7. Redmine\Api\IssueRelation
  8. Redmine\Api\IssueStatus
  9. Redmine\Api\Membership
  10. Redmine\Api\News
  11. Redmine\Api\Project
  12. Redmine\Api\Query
  13. Redmine\Api\Role
  14. Redmine\Api\Search
  15. Redmine\Api\TimeEntry
  16. Redmine\Api\TimeEntryActivity
  17. Redmine\Api\Tracker
  18. Redmine\Api\User
  19. Redmine\Api\Version
  20. Redmine\Api\Wiki
  21. Redmine\Api\AbstractApi
@Art4 Art4 changed the title Declare API classes as final Create factory methods in all API classes Feb 1, 2024
@Art4 Art4 added this to the v2.6.0 milestone Feb 1, 2024
@Art4 Art4 modified the milestones: v2.6.0, v2.7.0 Feb 16, 2024
@Art4 Art4 modified the milestones: v2.7.0, v2.8.0 Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant