Create factory methods in all API classes
Art4 opened this issue · comments
Artur Weigandt commented
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
Redmine\Api\Attachment
Redmine\Api\CustomField
Redmine\Api\Group
Redmine\Api\Issue
Redmine\Api\IssueCategory
Redmine\Api\IssuePriority
Redmine\Api\IssueRelation
Redmine\Api\IssueStatus
Redmine\Api\Membership
Redmine\Api\News
Redmine\Api\Project
Redmine\Api\Query
Redmine\Api\Role
Redmine\Api\Search
Redmine\Api\TimeEntry
Redmine\Api\TimeEntryActivity
Redmine\Api\Tracker
Redmine\Api\User
Redmine\Api\Version
Redmine\Api\Wiki
Redmine\Api\AbstractApi