summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoeland Jago Douma <roeland@famdouma.nl>2018-01-16 16:41:41 +0100
committerRoeland Jago Douma <roeland@famdouma.nl>2018-01-16 19:19:58 +0100
commita345605ec19e3e840cf9646bcd35377fb2c254a1 (patch)
tree31ddc564b6001c543ed35a4324607c5d19db2d84
parent13a787e2f5d22e4cd8204f4524ea3e2c4eba4d32 (diff)
downloadnextcloud-server-a345605ec19e3e840cf9646bcd35377fb2c254a1.tar.gz
nextcloud-server-a345605ec19e3e840cf9646bcd35377fb2c254a1.zip
Make OCP\Http strict
* Handle private files * Add return types * Add scalar typehints * Made strict * Fixed requiring proper guzzle message interface that is passed around Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
-rw-r--r--lib/private/Http/Client/Client.php28
-rw-r--r--lib/private/Http/Client/ClientService.php4
-rw-r--r--lib/private/Http/Client/Response.php11
-rw-r--r--lib/public/Http/Client/IClient.php13
-rw-r--r--lib/public/Http/Client/IClientService.php3
-rw-r--r--lib/public/Http/Client/IResponse.php9
6 files changed, 38 insertions, 30 deletions
diff --git a/lib/private/Http/Client/Client.php b/lib/private/Http/Client/Client.php
index 4697f2e038c..4e6843d7b9f 100644
--- a/lib/private/Http/Client/Client.php
+++ b/lib/private/Http/Client/Client.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -25,6 +26,7 @@ namespace OC\Http\Client;
use GuzzleHttp\Client as GuzzleClient;
use OCP\Http\Client\IClient;
+use OCP\Http\Client\IResponse;
use OCP\ICertificateManager;
use OCP\IConfig;
@@ -89,7 +91,7 @@ class Client implements IClient {
*
* @return string
*/
- private function getProxyUri() {
+ private function getProxyUri(): string {
$proxyHost = $this->config->getSystemValue('proxy', null);
$proxyUserPwd = $this->config->getSystemValue('proxyuserpwd', null);
$proxyUri = '';
@@ -130,10 +132,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function get($uri, array $options = []) {
+ public function get(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->get($uri, $options);
$isStream = isset($options['stream']) && $options['stream'];
@@ -161,10 +163,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function head($uri, $options = []) {
+ public function head(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->head($uri, $options);
return new Response($response);
@@ -196,10 +198,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function post($uri, array $options = []) {
+ public function post(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->post($uri, $options);
return new Response($response);
@@ -231,10 +233,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function put($uri, array $options = []) {
+ public function put(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->put($uri, $options);
return new Response($response);
@@ -266,10 +268,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function delete($uri, array $options = []) {
+ public function delete(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->delete($uri, $options);
return new Response($response);
@@ -302,10 +304,10 @@ class Client implements IClient {
* 'verify' => true, // bool or string to CA file
* 'debug' => true,
* 'timeout' => 5,
- * @return Response
+ * @return IResponse
* @throws \Exception If the request could not get completed
*/
- public function options($uri, array $options = []) {
+ public function options(string $uri, array $options = []): IResponse {
$this->setDefaultOptions();
$response = $this->client->options($uri, $options);
return new Response($response);
diff --git a/lib/private/Http/Client/ClientService.php b/lib/private/Http/Client/ClientService.php
index 108ffa709cf..1df54010a2d 100644
--- a/lib/private/Http/Client/ClientService.php
+++ b/lib/private/Http/Client/ClientService.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -23,6 +24,7 @@
namespace OC\Http\Client;
use GuzzleHttp\Client as GuzzleClient;
+use OCP\Http\Client\IClient;
use OCP\Http\Client\IClientService;
use OCP\ICertificateManager;
use OCP\IConfig;
@@ -51,7 +53,7 @@ class ClientService implements IClientService {
/**
* @return Client
*/
- public function newClient() {
+ public function newClient(): IClient {
return new Client($this->config, $this->certificateManager, new GuzzleClient());
}
}
diff --git a/lib/private/Http/Client/Response.php b/lib/private/Http/Client/Response.php
index 48885de9f3a..0ce6cc98e0d 100644
--- a/lib/private/Http/Client/Response.php
+++ b/lib/private/Http/Client/Response.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -24,7 +25,7 @@
namespace OC\Http\Client;
use OCP\Http\Client\IResponse;
-use GuzzleHttp\Message\Response as GuzzleResponse;
+use GuzzleHttp\Message\ResponseInterface as GuzzleResponse;
/**
* Class Response
@@ -61,22 +62,22 @@ class Response implements IResponse {
/**
* @return int
*/
- public function getStatusCode() {
+ public function getStatusCode(): int {
return $this->response->getStatusCode();
}
/**
- * @param $key
+ * @param string $key
* @return string
*/
- public function getHeader($key) {
+ public function getHeader(string $key): string {
return $this->response->getHeader($key);
}
/**
* @return array
*/
- public function getHeaders() {
+ public function getHeaders(): array {
return $this->response->getHeaders();
}
}
diff --git a/lib/public/Http/Client/IClient.php b/lib/public/Http/Client/IClient.php
index 49e679a7ade..50addc230eb 100644
--- a/lib/public/Http/Client/IClient.php
+++ b/lib/public/Http/Client/IClient.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -59,7 +60,7 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function get($uri, array $options = []);
+ public function get(string $uri, array $options = []): IResponse;
/**
* Sends a HEAD request
@@ -84,7 +85,7 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function head($uri, $options = []);
+ public function head(string $uri, array $options = []): IResponse;
/**
* Sends a POST request
@@ -114,7 +115,7 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function post($uri, array $options = []);
+ public function post(string $uri, array $options = []): IResponse;
/**
* Sends a PUT request
@@ -144,7 +145,7 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function put($uri, array $options = []);
+ public function put(string $uri, array $options = []): IResponse;
/**
* Sends a DELETE request
@@ -174,7 +175,7 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function delete($uri, array $options = []);
+ public function delete(string $uri, array $options = []): IResponse;
/**
* Sends a options request
@@ -204,5 +205,5 @@ interface IClient {
* @throws \Exception If the request could not get completed
* @since 8.1.0
*/
- public function options($uri, array $options = []);
+ public function options(string $uri, array $options = []): IResponse;
}
diff --git a/lib/public/Http/Client/IClientService.php b/lib/public/Http/Client/IClientService.php
index 09a1f1f7b40..d34302744e1 100644
--- a/lib/public/Http/Client/IClientService.php
+++ b/lib/public/Http/Client/IClientService.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -34,5 +35,5 @@ interface IClientService {
* @return IClient
* @since 8.1.0
*/
- public function newClient();
+ public function newClient(): IClient;
}
diff --git a/lib/public/Http/Client/IResponse.php b/lib/public/Http/Client/IResponse.php
index 94817f012b3..e935067d8c2 100644
--- a/lib/public/Http/Client/IResponse.php
+++ b/lib/public/Http/Client/IResponse.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
@@ -41,18 +42,18 @@ interface IResponse {
* @return int
* @since 8.1.0
*/
- public function getStatusCode();
+ public function getStatusCode(): int;
/**
- * @param $key
+ * @param string $key
* @return string
* @since 8.1.0
*/
- public function getHeader($key);
+ public function getHeader(string $key): string;
/**
* @return array
* @since 8.1.0
*/
- public function getHeaders();
+ public function getHeaders(): array;
}