There are two things about NameTableStore that make it (IMO) unreasonably hard to use:
- getID() lookups for non-existent names throw exceptions rather than returning a bottom value (e.g. null). This results in ugly try-catch blocks everywhere, and code review comments like this one. In particular, this code could have been a one-liner with array_map if null had been used instead of an exception.
- Passing in an ID field from the database to getName() throws an exception, because our DB stack returns strings rather than integers for these. $store->getName( $row->foo_id ) is intuitive to write, but it'll blow up in your face as this code did, because $row->foo_id is a string, and getName() throws an exception if you pass it anything other than an integer. This has already necessitated a revert to unbreak beta labs once, and it'll keep happening because nobody will remember to do $storage->getName( intval( $row->foo_id ) ).
I propose that getID() return null instead of throwing a NameTableAccessException, and that getName() cast string inputs to an integer (at the very least if they pass is_numeric()).