kbsali / php-redmine-api

A simple PHP Redmine API client, Object Oriented
MIT License
420 stars 183 forks source link

Deprecate all `Redmine\Api\*::getIdByName()` methods #417

Closed Art4 closed 3 months ago

Art4 commented 4 months ago

In #338 we have deprecated all listing() methods. These methods are the base for the getIdByName() methods.

Getting the ID by a name could easily made by using the new listNames() methods and array_search().

$name = 'Feature';

/** @var int|false */
- $id = $client->getApi('tracker')->getIdByName($name);
+ $id = array_search($name, $client->getApi('tracker')->listNames(), true);

However, some endpoints allow name duplications (e.g. projects and versions), so it might become difficult to decide witch ID should be chosen on a name collision.

Instead of editing this methods (to use the listNames() methods internally) and made prediction about name collisions I propose to deprecated them and let the user handle this situation.

Affected methods