PingPlusPlus / pingpp-php

MIT License
378 stars 182 forks source link

返回值和可能抛的Exception应该有更清晰的注释说明 #19

Open icedfish opened 9 years ago

icedfish commented 9 years ago
class Charge extends ApiResource
{
    /**
     * @param string $id The ID of the charge to retrieve.
     * @param array|string|null $options
     *
     * @return Charge
     */
    public static function retrieve($id, $options = null)
    {
        return self::_retrieve($id, $options);
    }

Charge类的多个方法实际上都是会抛Exception的,比如上述retrieve()方法在$id非法时就会抛InvalidRequestError。

希望官方在SDK各个常用方法上标准清楚可能返回的Exception类型,开发的时候IDE会对没有捕捉的Excetion进行提示,调用者能更清楚的知道如何应对返回。

     /** eg:
     * @throws InvalidRequestError if the error is caused by the user.
     * @throws AuthenticationError if the error is caused by a lack of
     *    permissions.
     * @throws ApiError otherwise.
     */

其实retrieve()何时会返回string或者null我到现在都没明白,所以校验返回的时候很痛苦,只检查是否抛Exception不知是否够用。 希望增加类似的说明。

samurai00 commented 9 years ago

@icedfish 我们的 Charge,Refund ... 这些类,理论上都有可能抛出我们定义的任何一种 Exception 的。 不过我们会改进说明的,谢谢你的建议。