Any time I need a specified enumeration of possible values, I'll always use individual constants to explicitly define all of them, e.g. const VALUE_1 = 'val_1';
, const VALUE_2 = 'val_2';
.
As for identifying what a default value should be, I agree with your approach of just having that second argument in callApi()
to set what the default would be (callApi()
), but to do so by using one of the actual constants rather than having another "default" constant that just points to one of the value constants. That way, you can set the main default in your base class, and if child classes want to choose their own defaults, they simply override the method.
Also, this allows you to specifically mention those various argument options in the @param
tag in the docblock for callApi()
.
Lastly, I'd suggest setting the constant values to simply be integers rather than strings. That way, since the values themselves will not be particularly informative, callers will be more likely to use the constant names when they do callApi()
, thus making their own code more readable and less likely to pass unexpected values.