From af0b45013ee29a6704cf4b71504fde718ef7299d Mon Sep 17 00:00:00 2001 From: Pierre Gordon Date: Thu, 2 Apr 2020 14:39:32 -0400 Subject: [PATCH] Add FailedRemoteRequest interface to mark exception classes related to remote requests --- lib/common/phpstan.neon.dist | 2 ++ lib/common/src/Exception/FailedRemoteRequest.php | 13 +++++++++++++ ...sponseData.php => FailedToGetCachedResponse.php} | 4 ++-- .../src/Exception/FailedToGetFromRemoteUrl.php | 2 +- lib/common/src/RemoteGetRequest.php | 4 ++-- .../src/RemoteRequest/CurlRemoteGetRequest.php | 3 ++- .../src/RemoteRequest/FallbackRemoteGetRequest.php | 4 ++-- .../RemoteRequest/FilesystemRemoteGetRequest.php | 3 ++- .../src/RemoteRequest/StubbedRemoteGetRequest.php | 4 ++-- src/RemoteRequest/CachedRemoteGetRequest.php | 7 ++++--- src/RemoteRequest/WpHttpRemoteGetRequest.php | 3 ++- 11 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 lib/common/src/Exception/FailedRemoteRequest.php rename lib/common/src/Exception/{FailedToGetCachedResponseData.php => FailedToGetCachedResponse.php} (73%) diff --git a/lib/common/phpstan.neon.dist b/lib/common/phpstan.neon.dist index 1857a8b4809..fb2b62bf871 100644 --- a/lib/common/phpstan.neon.dist +++ b/lib/common/phpstan.neon.dist @@ -8,3 +8,5 @@ parameters: - %currentWorkingDirectory%/src/ autoload_files: - %currentWorkingDirectory%/vendor/autoload.php + ignoreErrors: + - '#^PHPDoc tag @throws with type AmpProject\\Exception\\FailedRemoteRequest is not subtype of Throwable$#' diff --git a/lib/common/src/Exception/FailedRemoteRequest.php b/lib/common/src/Exception/FailedRemoteRequest.php new file mode 100644 index 00000000000..0a03765943b --- /dev/null +++ b/lib/common/src/Exception/FailedRemoteRequest.php @@ -0,0 +1,13 @@ +is_valid() ) { - throw new FailedToGetCachedResponseData( $url ); + throw new FailedToGetCachedResponse( $url ); } return new RemoteGetRequestResponse( $cached_response->get_body(), $cached_response->get_headers(), $cached_response->get_status_code() ); diff --git a/src/RemoteRequest/WpHttpRemoteGetRequest.php b/src/RemoteRequest/WpHttpRemoteGetRequest.php index 2f08364456c..f1e5d73768e 100644 --- a/src/RemoteRequest/WpHttpRemoteGetRequest.php +++ b/src/RemoteRequest/WpHttpRemoteGetRequest.php @@ -7,6 +7,7 @@ namespace AmpProject\AmpWP\RemoteRequest; +use AmpProject\Exception\FailedRemoteRequest; use AmpProject\Exception\FailedToGetFromRemoteUrl; use AmpProject\RemoteGetRequest; use AmpProject\RemoteRequest\RemoteGetRequestResponse; @@ -98,7 +99,7 @@ public function __construct( $ssl_verify = true, $timeout = self::DEFAULT_TIMEOU * * @param string $url URL to get. * @return Response Response for the executed request. - * @throws FailedToGetFromRemoteUrl If retrieving the contents from the URL failed. + * @throws FailedRemoteRequest If retrieving the contents from the URL failed. */ public function get( $url ) { $retries_left = $this->retries;