HomePhabricator

Add "phutil_describe_type()" and clean up a few obscure things in "libphutil/"

Description

Add "phutil_describe_type()" and clean up a few obscure things in "libphutil/"

Summary:
See PHI1096. With some frequency, I want to raise an exception like "expected method getSomething() to return an object of type X, but it actually returned a thing of type Y".

There's no great builtin function for producing a good value for "Y", the unexpected value's type. "get_type()" is somewhat close, but just returns "object" for objects, when we'd prefer to return the object's class name since this is significantly more useful.

We have a pretty good method for producing "Y" in "libphutil/", but it's hard to remember: PhutilTypeSpec::getTypeOf($value). Wrap it in a convenient name, phutil_describe_type().

Also, provide phutil_is_natural_list() for simplifying the array_keys(...) === range(...) test that we have in a handful of cases.

Finally, clean up a couple of error behaviors that give you a bad/misleading error if you make a syntax error in "utils.php" specifically.

Test Plan: Ran unit tests, see also next diff.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D20213

Details

Provenance
epriestleyAuthored on Feb 26 2019, 3:02 AM
epriestleyPushed on Feb 28 2019, 3:10 PM
Reviewer
amckinley
Differential Revision
D20213: Add "phutil_describe_type()" and clean up a few obscure things in "libphutil/"
Parents
rPHU0679917944e1: Refine checks against "cwd" before "proc_open()"
Branches
Unknown
Tags
Unknown
Build Status
Buildable 22136
Build 30248: Run Core Tests