protected static function mustBeStringOrScalar($arg, $arg_name = null)
    {
        if (
            !is_scalar($arg)
            &&
            !(is_object($arg) && method_exists($arg, '__toString'))
        ) {
            throw new \InvalidArgumentException(
                sprintf(
                    '%s must be a primitive scalar PHP type or object '
                    .'having `__toString()` method',
                    is_null($arg_name) ? 'Argument' : $arg_name
                    )
            );
        }
    }