Completed
Pull Request — master (#6651)
by Robin
14:19
created
lib/private/Remote/Api/ApiBase.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@
 block discarded – undo
56 56
 	 * @param array $body
57 57
 	 * @param array $query
58 58
 	 * @param array $headers
59
-	 * @return resource|string
59
+	 * @return string
60 60
 	 */
61 61
 	protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
62 62
 		$fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url;
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -26,71 +26,71 @@
 block discarded – undo
26 26
 use OCP\Http\Client\IClientService;
27 27
 
28 28
 class ApiBase {
29
-	/** @var Instance */
30
-	private $instance;
31
-	/** @var Credentials */
32
-	private $credentials;
33
-	/** @var IClientService */
34
-	private $clientService;
29
+    /** @var Instance */
30
+    private $instance;
31
+    /** @var Credentials */
32
+    private $credentials;
33
+    /** @var IClientService */
34
+    private $clientService;
35 35
 
36
-	public function __construct(Instance $instance, Credentials $credentials, IClientService $clientService) {
37
-		$this->instance = $instance;
38
-		$this->credentials = $credentials;
39
-		$this->clientService = $clientService;
40
-	}
36
+    public function __construct(Instance $instance, Credentials $credentials, IClientService $clientService) {
37
+        $this->instance = $instance;
38
+        $this->credentials = $credentials;
39
+        $this->clientService = $clientService;
40
+    }
41 41
 
42
-	protected function getHttpClient() {
43
-		return $this->clientService->newClient();
44
-	}
42
+    protected function getHttpClient() {
43
+        return $this->clientService->newClient();
44
+    }
45 45
 
46
-	protected function addDefaultHeaders(array $headers) {
47
-		return array_merge([
48
-			'OCS-APIREQUEST' => 'true',
49
-			'Accept' => 'application/json'
50
-		], $headers);
51
-	}
46
+    protected function addDefaultHeaders(array $headers) {
47
+        return array_merge([
48
+            'OCS-APIREQUEST' => 'true',
49
+            'Accept' => 'application/json'
50
+        ], $headers);
51
+    }
52 52
 
53
-	/**
54
-	 * @param string $method
55
-	 * @param string $url
56
-	 * @param array $body
57
-	 * @param array $query
58
-	 * @param array $headers
59
-	 * @return resource|string
60
-	 */
61
-	protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
62
-		$fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url;
63
-		$options = [
64
-			'query' => $query,
65
-			'headers' => $this->addDefaultHeaders($headers),
66
-			'auth' => [$this->credentials->getUsername(), $this->credentials->getPassword()]
67
-		];
68
-		if ($body) {
69
-			$options['body'] = $body;
70
-		}
53
+    /**
54
+     * @param string $method
55
+     * @param string $url
56
+     * @param array $body
57
+     * @param array $query
58
+     * @param array $headers
59
+     * @return resource|string
60
+     */
61
+    protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
62
+        $fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url;
63
+        $options = [
64
+            'query' => $query,
65
+            'headers' => $this->addDefaultHeaders($headers),
66
+            'auth' => [$this->credentials->getUsername(), $this->credentials->getPassword()]
67
+        ];
68
+        if ($body) {
69
+            $options['body'] = $body;
70
+        }
71 71
 
72
-		$client = $this->getHttpClient();
72
+        $client = $this->getHttpClient();
73 73
 
74
-		switch ($method) {
75
-			case 'get':
76
-				$response = $client->get($fullUrl, $options);
77
-				break;
78
-			case 'post':
79
-				$response = $client->post($fullUrl, $options);
80
-				break;
81
-			case 'put':
82
-				$response = $client->put($fullUrl, $options);
83
-				break;
84
-			case 'delete':
85
-				$response = $client->delete($fullUrl, $options);
86
-				break;
87
-			case 'options':
88
-				$response = $client->options($fullUrl, $options);
89
-				break;
90
-			default:
91
-				throw new \InvalidArgumentException('Invalid method ' . $method);
92
-		}
74
+        switch ($method) {
75
+            case 'get':
76
+                $response = $client->get($fullUrl, $options);
77
+                break;
78
+            case 'post':
79
+                $response = $client->post($fullUrl, $options);
80
+                break;
81
+            case 'put':
82
+                $response = $client->put($fullUrl, $options);
83
+                break;
84
+            case 'delete':
85
+                $response = $client->delete($fullUrl, $options);
86
+                break;
87
+            case 'options':
88
+                $response = $client->options($fullUrl, $options);
89
+                break;
90
+            default:
91
+                throw new \InvalidArgumentException('Invalid method ' . $method);
92
+        }
93 93
 
94
-		return $response->getBody();
95
-	}
94
+        return $response->getBody();
95
+    }
96 96
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 * @return resource|string
60 60
 	 */
61 61
 	protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
62
-		$fullUrl = trim($this->instance->getFullUrl(), '/') . '/' . $url;
62
+		$fullUrl = trim($this->instance->getFullUrl(), '/').'/'.$url;
63 63
 		$options = [
64 64
 			'query' => $query,
65 65
 			'headers' => $this->addDefaultHeaders($headers),
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 				$response = $client->options($fullUrl, $options);
89 89
 				break;
90 90
 			default:
91
-				throw new \InvalidArgumentException('Invalid method ' . $method);
91
+				throw new \InvalidArgumentException('Invalid method '.$method);
92 92
 		}
93 93
 
94 94
 		return $response->getBody();
Please login to merge, or discard this patch.
lib/private/Remote/Instance.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -116,6 +116,9 @@
 block discarded – undo
116 116
 		return $status;
117 117
 	}
118 118
 
119
+	/**
120
+	 * @param string $url
121
+	 */
119 122
 	private function downloadStatus($url) {
120 123
 		try {
121 124
 			$request = $this->clientService->newClient()->get($url);
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -28,100 +28,100 @@
 block discarded – undo
28 28
  * Provides some basic info about a remote Nextcloud instance
29 29
  */
30 30
 class Instance {
31
-	/** @var string */
32
-	private $url;
31
+    /** @var string */
32
+    private $url;
33 33
 
34
-	/** @var ICache */
35
-	private $cache;
34
+    /** @var ICache */
35
+    private $cache;
36 36
 
37
-	/** @var IClientService */
38
-	private $clientService;
37
+    /** @var IClientService */
38
+    private $clientService;
39 39
 
40
-	private $status;
40
+    private $status;
41 41
 
42
-	/**
43
-	 * @param string $url
44
-	 * @param ICache $cache
45
-	 * @param IClientService $clientService
46
-	 */
47
-	public function __construct($url, ICache $cache, IClientService $clientService) {
48
-		$url = str_replace('https://', '', $url);
49
-		$this->url = str_replace('http://', '', $url);
50
-		$this->cache = $cache;
51
-		$this->clientService;
52
-	}
42
+    /**
43
+     * @param string $url
44
+     * @param ICache $cache
45
+     * @param IClientService $clientService
46
+     */
47
+    public function __construct($url, ICache $cache, IClientService $clientService) {
48
+        $url = str_replace('https://', '', $url);
49
+        $this->url = str_replace('http://', '', $url);
50
+        $this->cache = $cache;
51
+        $this->clientService;
52
+    }
53 53
 
54
-	/**
55
-	 * @return string The url of the remote server without protocol
56
-	 */
57
-	public function getUrl() {
58
-		return $this->url;
59
-	}
54
+    /**
55
+     * @return string The url of the remote server without protocol
56
+     */
57
+    public function getUrl() {
58
+        return $this->url;
59
+    }
60 60
 
61
-	/**
62
-	 * @return string The of of the remote server with protocol
63
-	 */
64
-	public function getFullUrl() {
65
-		return $this->getProtocol() . '://' . $this->getUrl();
66
-	}
61
+    /**
62
+     * @return string The of of the remote server with protocol
63
+     */
64
+    public function getFullUrl() {
65
+        return $this->getProtocol() . '://' . $this->getUrl();
66
+    }
67 67
 
68
-	/**
69
-	 * @return string The full version string in '13.1.2.3' format
70
-	 */
71
-	public function getVersion() {
72
-		$status = $this->getStatus();
73
-		return $status['version'];
74
-	}
68
+    /**
69
+     * @return string The full version string in '13.1.2.3' format
70
+     */
71
+    public function getVersion() {
72
+        $status = $this->getStatus();
73
+        return $status['version'];
74
+    }
75 75
 
76
-	/**
77
-	 * @return string 'http' or 'https'
78
-	 */
79
-	public function getProtocol() {
80
-		$status = $this->getStatus();
81
-		return $status['protocol'];
82
-	}
76
+    /**
77
+     * @return string 'http' or 'https'
78
+     */
79
+    public function getProtocol() {
80
+        $status = $this->getStatus();
81
+        return $status['protocol'];
82
+    }
83 83
 
84
-	/**
85
-	 * Check that the remote server is installed and not in maintenance mode
86
-	 *
87
-	 * @return bool
88
-	 */
89
-	public function isActive() {
90
-		$status = $this->getStatus();
91
-		return $status['installed'] && !$status['maintenance'];
92
-	}
84
+    /**
85
+     * Check that the remote server is installed and not in maintenance mode
86
+     *
87
+     * @return bool
88
+     */
89
+    public function isActive() {
90
+        $status = $this->getStatus();
91
+        return $status['installed'] && !$status['maintenance'];
92
+    }
93 93
 
94
-	private function getStatus() {
95
-		if ($this->status) {
96
-			return $this->status;
97
-		}
98
-		$key = 'remote/' . $this->url . '/status';
99
-		$status = $this->cache->get($key);
100
-		if (!$status) {
101
-			$response = $this->downloadStatus('https://' . $this->getUrl() . '/status.php');
102
-			$protocol = 'https';
103
-			if (!$response) {
104
-				$response = $this->downloadStatus('http://' . $this->getUrl() . '/status.php');
105
-				$protocol = 'http';
106
-			}
107
-			$status = json_decode($response, true);
108
-			if ($status) {
109
-				$status['protocol'] = $protocol;
110
-			}
111
-			if ($status) {
112
-				$this->cache->set($key, $status, 5 * 60);
113
-				$this->status = $status;
114
-			}
115
-		}
116
-		return $status;
117
-	}
94
+    private function getStatus() {
95
+        if ($this->status) {
96
+            return $this->status;
97
+        }
98
+        $key = 'remote/' . $this->url . '/status';
99
+        $status = $this->cache->get($key);
100
+        if (!$status) {
101
+            $response = $this->downloadStatus('https://' . $this->getUrl() . '/status.php');
102
+            $protocol = 'https';
103
+            if (!$response) {
104
+                $response = $this->downloadStatus('http://' . $this->getUrl() . '/status.php');
105
+                $protocol = 'http';
106
+            }
107
+            $status = json_decode($response, true);
108
+            if ($status) {
109
+                $status['protocol'] = $protocol;
110
+            }
111
+            if ($status) {
112
+                $this->cache->set($key, $status, 5 * 60);
113
+                $this->status = $status;
114
+            }
115
+        }
116
+        return $status;
117
+    }
118 118
 
119
-	private function downloadStatus($url) {
120
-		try {
121
-			$request = $this->clientService->newClient()->get($url);
122
-			return $request->getBody();
123
-		} catch (\Exception $e) {
124
-			return false;
125
-		}
126
-	}
119
+    private function downloadStatus($url) {
120
+        try {
121
+            $request = $this->clientService->newClient()->get($url);
122
+            return $request->getBody();
123
+        } catch (\Exception $e) {
124
+            return false;
125
+        }
126
+    }
127 127
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
 	 * @return string The of of the remote server with protocol
63 63
 	 */
64 64
 	public function getFullUrl() {
65
-		return $this->getProtocol() . '://' . $this->getUrl();
65
+		return $this->getProtocol().'://'.$this->getUrl();
66 66
 	}
67 67
 
68 68
 	/**
@@ -95,13 +95,13 @@  discard block
 block discarded – undo
95 95
 		if ($this->status) {
96 96
 			return $this->status;
97 97
 		}
98
-		$key = 'remote/' . $this->url . '/status';
98
+		$key = 'remote/'.$this->url.'/status';
99 99
 		$status = $this->cache->get($key);
100 100
 		if (!$status) {
101
-			$response = $this->downloadStatus('https://' . $this->getUrl() . '/status.php');
101
+			$response = $this->downloadStatus('https://'.$this->getUrl().'/status.php');
102 102
 			$protocol = 'https';
103 103
 			if (!$response) {
104
-				$response = $this->downloadStatus('http://' . $this->getUrl() . '/status.php');
104
+				$response = $this->downloadStatus('http://'.$this->getUrl().'/status.php');
105 105
 				$protocol = 'http';
106 106
 			}
107 107
 			$status = json_decode($response, true);
Please login to merge, or discard this patch.
lib/private/Remote/User.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -23,102 +23,102 @@
 block discarded – undo
23 23
 
24 24
 
25 25
 class User {
26
-	/** @var array */
27
-	private $data;
28
-
29
-	public function __construct(array $data) {
30
-		$this->data = $data;
31
-	}
32
-
33
-
34
-	/**
35
-	 * @return string
36
-	 */
37
-	public function getUserId() {
38
-		return $this->data['id'];
39
-	}
40
-
41
-	/**
42
-	 * @return string
43
-	 */
44
-	public function getEmail() {
45
-		return $this->data['email'];
46
-	}
47
-
48
-	/**
49
-	 * @return string
50
-	 */
51
-	public function getDisplayName() {
52
-		return $this->data['displayname'];
53
-	}
54
-
55
-	/**
56
-	 * @return string
57
-	 */
58
-	public function getPhone() {
59
-		return $this->data['phone'];
60
-	}
61
-
62
-	/**
63
-	 * @return string
64
-	 */
65
-	public function getAddress() {
66
-		return $this->data['address'];
67
-	}
68
-
69
-	/**
70
-	 * @return string
71
-	 */
72
-	public function getWebsite() {
73
-		return $this->data['website'];
74
-	}
75
-
76
-	/**
77
-	 * @return string
78
-	 */
79
-	public function getTwitter() {
80
-		return $this->data['twitter'];
81
-	}
82
-
83
-	/**
84
-	 * @return string[]
85
-	 */
86
-	public function getGroups() {
87
-		return $this->data['groups'];
88
-	}
89
-
90
-	/**
91
-	 * @return string
92
-	 */
93
-	public function getLanguage() {
94
-		return $this->data['language'];
95
-	}
96
-
97
-	/**
98
-	 * @return int
99
-	 */
100
-	public function getUsedSpace() {
101
-		return $this->data['quota']['used'];
102
-	}
103
-
104
-	/**
105
-	 * @return int
106
-	 */
107
-	public function getFreeSpace() {
108
-		return $this->data['quota']['free'];
109
-	}
110
-
111
-	/**
112
-	 * @return int
113
-	 */
114
-	public function getTotalSpace() {
115
-		return $this->data['quota']['total'];
116
-	}
117
-
118
-	/**
119
-	 * @return int
120
-	 */
121
-	public function getQuota() {
122
-		return $this->data['quota']['quota'];
123
-	}
26
+    /** @var array */
27
+    private $data;
28
+
29
+    public function __construct(array $data) {
30
+        $this->data = $data;
31
+    }
32
+
33
+
34
+    /**
35
+     * @return string
36
+     */
37
+    public function getUserId() {
38
+        return $this->data['id'];
39
+    }
40
+
41
+    /**
42
+     * @return string
43
+     */
44
+    public function getEmail() {
45
+        return $this->data['email'];
46
+    }
47
+
48
+    /**
49
+     * @return string
50
+     */
51
+    public function getDisplayName() {
52
+        return $this->data['displayname'];
53
+    }
54
+
55
+    /**
56
+     * @return string
57
+     */
58
+    public function getPhone() {
59
+        return $this->data['phone'];
60
+    }
61
+
62
+    /**
63
+     * @return string
64
+     */
65
+    public function getAddress() {
66
+        return $this->data['address'];
67
+    }
68
+
69
+    /**
70
+     * @return string
71
+     */
72
+    public function getWebsite() {
73
+        return $this->data['website'];
74
+    }
75
+
76
+    /**
77
+     * @return string
78
+     */
79
+    public function getTwitter() {
80
+        return $this->data['twitter'];
81
+    }
82
+
83
+    /**
84
+     * @return string[]
85
+     */
86
+    public function getGroups() {
87
+        return $this->data['groups'];
88
+    }
89
+
90
+    /**
91
+     * @return string
92
+     */
93
+    public function getLanguage() {
94
+        return $this->data['language'];
95
+    }
96
+
97
+    /**
98
+     * @return int
99
+     */
100
+    public function getUsedSpace() {
101
+        return $this->data['quota']['used'];
102
+    }
103
+
104
+    /**
105
+     * @return int
106
+     */
107
+    public function getFreeSpace() {
108
+        return $this->data['quota']['free'];
109
+    }
110
+
111
+    /**
112
+     * @return int
113
+     */
114
+    public function getTotalSpace() {
115
+        return $this->data['quota']['total'];
116
+    }
117
+
118
+    /**
119
+     * @return int
120
+     */
121
+    public function getQuota() {
122
+        return $this->data['quota']['quota'];
123
+    }
124 124
 }
Please login to merge, or discard this patch.
lib/private/Remote/Api/OCS.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -27,33 +27,33 @@
 block discarded – undo
27 27
 use OCP\API;
28 28
 
29 29
 class OCS extends ApiBase {
30
-	/**
31
-	 * @param string $method
32
-	 * @param string $url
33
-	 * @param array $body
34
-	 * @param array $query
35
-	 * @param array $headers
36
-	 * @return array
37
-	 * @throws ForbiddenException
38
-	 * @throws NotFoundException
39
-	 */
40
-	protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
41
-		$response = json_decode(parent::request($method, $url, $body, $query, $headers), true);
42
-		if ($response['ocs']['meta']['status'] === API::RESPOND_UNAUTHORISED) {
43
-			throw new ForbiddenException();
44
-		}
45
-		if ($response['ocs']['meta']['status'] === API::RESPOND_NOT_FOUND) {
46
-			throw new NotFoundException();
47
-		}
30
+    /**
31
+     * @param string $method
32
+     * @param string $url
33
+     * @param array $body
34
+     * @param array $query
35
+     * @param array $headers
36
+     * @return array
37
+     * @throws ForbiddenException
38
+     * @throws NotFoundException
39
+     */
40
+    protected function request($method, $url, array $body = [], array $query = [], array $headers = []) {
41
+        $response = json_decode(parent::request($method, $url, $body, $query, $headers), true);
42
+        if ($response['ocs']['meta']['status'] === API::RESPOND_UNAUTHORISED) {
43
+            throw new ForbiddenException();
44
+        }
45
+        if ($response['ocs']['meta']['status'] === API::RESPOND_NOT_FOUND) {
46
+            throw new NotFoundException();
47
+        }
48 48
 
49
-		return $response['ocs']['data'];
50
-	}
49
+        return $response['ocs']['data'];
50
+    }
51 51
 
52
-	public function getUser($userId) {
53
-		return new User($this->request('get', '/ocs/v1.php/cloud/users/' . $userId));
54
-	}
52
+    public function getUser($userId) {
53
+        return new User($this->request('get', '/ocs/v1.php/cloud/users/' . $userId));
54
+    }
55 55
 
56
-	public function getCapabilities() {
57
-		return $this->request('get', '/ocs/v1.php/cloud/capabilities');
58
-	}
56
+    public function getCapabilities() {
57
+        return $this->request('get', '/ocs/v1.php/cloud/capabilities');
58
+    }
59 59
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@
 block discarded – undo
50 50
 	}
51 51
 
52 52
 	public function getUser($userId) {
53
-		return new User($this->request('get', '/ocs/v1.php/cloud/users/' . $userId));
53
+		return new User($this->request('get', '/ocs/v1.php/cloud/users/'.$userId));
54 54
 	}
55 55
 
56 56
 	public function getCapabilities() {
Please login to merge, or discard this patch.
lib/private/Remote/Credentials.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,31 +23,31 @@
 block discarded – undo
23 23
 
24 24
 
25 25
 class Credentials {
26
-	/** @var string */
27
-	private $user;
28
-	/** @var string */
29
-	private $password;
26
+    /** @var string */
27
+    private $user;
28
+    /** @var string */
29
+    private $password;
30 30
 
31
-	/**
32
-	 * @param string $user
33
-	 * @param string $password
34
-	 */
35
-	public function __construct($user, $password) {
36
-		$this->user = $user;
37
-		$this->password = $password;
38
-	}
31
+    /**
32
+     * @param string $user
33
+     * @param string $password
34
+     */
35
+    public function __construct($user, $password) {
36
+        $this->user = $user;
37
+        $this->password = $password;
38
+    }
39 39
 
40
-	/**
41
-	 * @return string
42
-	 */
43
-	public function getUsername() {
44
-		return $this->user;
45
-	}
40
+    /**
41
+     * @return string
42
+     */
43
+    public function getUsername() {
44
+        return $this->user;
45
+    }
46 46
 
47
-	/**
48
-	 * @return string
49
-	 */
50
-	public function getPassword() {
51
-		return $this->password;
52
-	}
47
+    /**
48
+     * @return string
49
+     */
50
+    public function getPassword() {
51
+        return $this->password;
52
+    }
53 53
 }
Please login to merge, or discard this patch.