Completed
Pull Request — master (#12)
by Piotr
02:39
created
controller/paperhivecontroller.php 2 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *	 *
122 122
 	 * @param string $dir
123 123
 	 * @param string $filename
124
-	 * @return string/boolean - returns PaperHive ID or false in case of error
124
+	 * @return string - returns PaperHive ID or false in case of error
125 125
 	 */
126 126
 	private function loadPaperHiveIdFromFile($dir, $filename) {
127 127
 		$path = $dir . '/' . $filename;
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @NoAdminRequired
229 229
 	 *
230 230
 	 * @param string $bookID
231
-	 * @return string/boolean
231
+	 * @return string
232 232
 	 */
233 233
 	private function fetchDocument($bookID) {
234 234
 		$urlDocument = $this->paperhive_base_url . $this->paperhive_api_url . $bookID;
@@ -316,7 +316,6 @@  discard block
 block discarded – undo
316 316
 	 *
317 317
 	 * @NoAdminRequired
318 318
 	 *
319
-	 * @param string $bookID
320 319
 	 * @return DataResponse
321 320
 	 */
322 321
 	public function getPaperHiveDetails() {
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 use OCP\IRequest;
34 34
 use OCP\Lock\LockedException;
35 35
 
36
-class PaperHiveController extends Controller{
36
+class PaperHiveController extends Controller {
37 37
 
38 38
 	/** @var IL10N */
39 39
 	private $l;
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	private function loadPaperHiveIdFromFile($dir, $filename) {
127 127
 		$path = $dir . '/' . $filename;
128
-		if (!$this->view->file_exists($path)){
128
+		if (!$this->view->file_exists($path)) {
129 129
 			return false;
130 130
 		}
131 131
 		
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 			$paperHiveObject = json_decode($fileContents, true);
135 135
 			if (json_last_error() === JSON_ERROR_NONE && isset($paperHiveObject['id'])) {
136 136
 				$paperHiveId = $paperHiveObject['id'];
137
-				if($this->adjustPaperHiveExtensions($path, $paperHiveId)){
137
+				if ($this->adjustPaperHiveExtensions($path, $paperHiveId)) {
138 138
 					return $paperHiveId;
139 139
 				}
140 140
 			}
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
 			if (sizeof($filenameParts) > 1) {
159 159
 				// Correct, file needs filename and extension
160 160
 				if (sizeof($filenameParts) === 2 || (sizeof($filenameParts) > 2 &&
161
-						strpos('.'.$filenameParts[sizeof($filenameParts)-2],$this->paperhive_rev_extension) === false)){
161
+						strpos('.' . $filenameParts[sizeof($filenameParts) - 2], $this->paperhive_rev_extension) === false)) {
162 162
 					// File needs correction, since been renamed or is obsolete
163 163
 					$revision = $this->loadPaperHiveIdFromFile($dir, $filename);
164
-					if ($revision === false){
164
+					if ($revision === false) {
165 165
 						return new DataResponse(['message' => (string)$this->l->t('File is obsolete, incorrectly renamed or cannot be read.')], Http::STATUS_BAD_REQUEST);
166 166
 					}
167 167
 				} else {
168 168
 					// File has correct format, and revision is the second extension
169 169
 					// Add extension dot since explode removed it and replace rev extension with empty string
170
-					$revisionString = '.'.$filenameParts[sizeof($filenameParts)-2];
170
+					$revisionString = '.' . $filenameParts[sizeof($filenameParts) - 2];
171 171
 					$revision = str_replace($this->paperhive_rev_extension, '', $revisionString);
172 172
 				}
173 173
 
@@ -194,7 +194,7 @@  discard block
 block discarded – undo
194 194
 			}
195 195
 
196 196
 		} catch (LockedException $e) {
197
-			$message = (string) $this->l->t('The file is locked.');
197
+			$message = (string)$this->l->t('The file is locked.');
198 198
 			return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
199 199
 		} catch (ForbiddenException $e) {
200 200
 			return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
@@ -274,7 +274,7 @@  discard block
 block discarded – undo
274 274
 			$extension = $this->paperhive_rev_extension . $bookID . $this->paperhive_file_extension;
275 275
 			$filename = $paperHiveObject['title'] . $extension;
276 276
 
277
-			if($dir == '/') {
277
+			if ($dir == '/') {
278 278
 				$path = $dir . $filename;
279 279
 			} else {
280 280
 				$path = $dir . '/' . $filename;
@@ -283,14 +283,14 @@  discard block
 block discarded – undo
283 283
 			try {
284 284
 				$exists = $this->view->file_exists($path);
285 285
 				if ($exists) {
286
-					$message = (string) $this->l->t('The file already exists.');
286
+					$message = (string)$this->l->t('The file already exists.');
287 287
 					return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
288 288
 				}
289 289
 				$filecontents = iconv(mb_detect_encoding($paperHiveString), "UTF-8", $paperHiveString);
290 290
 				try {
291 291
 					$this->view->file_put_contents($path, $filecontents);
292 292
 				} catch (LockedException $e) {
293
-					$message = (string) $this->l->t('The file is locked.');
293
+					$message = (string)$this->l->t('The file is locked.');
294 294
 					return new DataResponse(['message' => $message], Http::STATUS_BAD_REQUEST);
295 295
 				} catch (ForbiddenException $e) {
296 296
 					return new DataResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
Please login to merge, or discard this patch.
tests/controller/paperhivecontrollertest.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -90,6 +90,9 @@
 block discarded – undo
90 90
 			$this->clientMock);
91 91
 	}
92 92
 
93
+	/**
94
+	 * @param string $title
95
+	 */
93 96
 	private function fakeAll($bookID, $title) {
94 97
 		$contentsDoc = '{' . '"id" : "'.$bookID .'", "title" : "'. $title .'" }';
95 98
 		$contentsDis = '{' . '"discussions" : [ "blabla", "blabla" ]' .'}';
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,6 @@
 block discarded – undo
21 21
 
22 22
 namespace OCA\Files_PaperHive\Tests\Controller;
23 23
 
24
-use OC\HintException;
25 24
 use OCA\Files_PaperHive\Controller\PaperHiveController;
26 25
 use OCP\Files\ForbiddenException;
27 26
 use OCP\Lock\LockedException;
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -91,8 +91,8 @@  discard block
 block discarded – undo
91 91
 	}
92 92
 
93 93
 	private function fakeAll($bookID, $title) {
94
-		$contentsDoc = '{' . '"id" : "'.$bookID .'", "title" : "'. $title .'" }';
95
-		$contentsDis = '{' . '"discussions" : [ "blabla", "blabla" ]' .'}';
94
+		$contentsDoc = '{' . '"id" : "' . $bookID . '", "title" : "' . $title . '" }';
95
+		$contentsDis = '{' . '"discussions" : [ "blabla", "blabla" ]' . '}';
96 96
 		$this->responseMock->expects($this->any())
97 97
 			->method('getBody')
98 98
 			->willReturnOnConsecutiveCalls($contentsDis, $contentsDoc);
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 		$dir = '';
142 142
 		$bookID = 'Ra5WnkxImoOE';
143 143
 		$title = "Borderland City in New India";
144
-		$path = $dir . '/'. $title. '.renamed.paperhive';
144
+		$path = $dir . '/' . $title . '.renamed.paperhive';
145 145
 		$contents = $this->fakeAll($bookID, $title);
146 146
 
147 147
 		$this->viewMock->expects($this->once())
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 		$dir = '';
171 171
 		$bookID = 'Ra5WnkxImoOE';
172 172
 		$title = "Borderland City in New India";
173
-		$path = $dir . '/'. $title;
173
+		$path = $dir . '/' . $title;
174 174
 		$contents = $this->fakeAll($bookID, $title);
175 175
 
176 176
 		$result = $this->controller->loadMetadata('/', $path, "true");
@@ -185,7 +185,7 @@  discard block
 block discarded – undo
185 185
 		$dir = '';
186 186
 		$bookID = 'Ra5WnkxImoOE';
187 187
 		$title = "Borderland City in New India";
188
-		$path = $dir . '/'. $title. '.renamed.paperhive';
188
+		$path = $dir . '/' . $title . '.renamed.paperhive';
189 189
 		$contents = $this->fakeAll($bookID, $title);
190 190
 
191 191
 		$this->viewMock->expects($this->once())
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 		$dir = '';
205 205
 		$bookID = 'Ra5WnkxImoOE';
206 206
 		$title = "Borderland City in New India";
207
-		$path = $dir . '/'. $title. '.renamed.paperhive';
207
+		$path = $dir . '/' . $title . '.renamed.paperhive';
208 208
 		$contents = $this->fakeAll($bookID, $title);
209 209
 
210 210
 		$this->viewMock->expects($this->once())
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
 	$dir = '';
228 228
 	$bookID = 'Ra5WnkxImoOE';
229 229
 	$title = "Borderland City in New India";
230
-	$path = $dir . '/'. $title. '.renamed.paperhive';
230
+	$path = $dir . '/' . $title . '.renamed.paperhive';
231 231
 	$contents = $this->fakeAll($bookID, $title);
232 232
 
233 233
 	$this->viewMock->expects($this->once())
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 		$dir = '';
255 255
 		$bookID = 'Ra5WnkxImoOE';
256 256
 		$title = "Borderland City in New India";
257
-		$path = $dir . '/'. $title. '.renamed.paperhive';
257
+		$path = $dir . '/' . $title . '.renamed.paperhive';
258 258
 		$contents = $this->fakeAll($bookID, $title);
259 259
 
260 260
 		$this->viewMock->expects($this->once())
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 		$dir = '';
289 289
 		$bookID = 'Ra5WnkxImoOE';
290 290
 		$title = "Borderland City in New India";
291
-		$path = $dir . '/'. $title. '.rev'.$bookID.'.paperhive';
291
+		$path = $dir . '/' . $title . '.rev' . $bookID . '.paperhive';
292 292
 
293 293
 		$result = $this->controller->loadMetadata('/', $path, "false");
294 294
 		$data = $result->getData();
@@ -309,7 +309,7 @@  discard block
 block discarded – undo
309 309
 		$dir = '';
310 310
 		$bookID = 'Ra5WnkxImoOE';
311 311
 		$title = "Borderland City in New India";
312
-		$path = $dir . '/'. $title. '.rev'.$bookID.'.paperhive';
312
+		$path = $dir . '/' . $title . '.rev' . $bookID . '.paperhive';
313 313
 		$contents = $this->fakeAll($bookID, $title);
314 314
 
315 315
 		$result = $this->controller->loadMetadata('/', $path, "true");
@@ -328,7 +328,7 @@  discard block
 block discarded – undo
328 328
 	}
329 329
 
330 330
 	public function dataTestSave() {
331
-		return array (
331
+		return array(
332 332
 			array('', 'Ra5WnkxImoOE', true, true, 200, ''),
333 333
 			array('/test', 'Ra5WnkxImoOE', true, true, 200, ''),
334 334
 			array('', 'Ra5WnkxImoOE', true, true, 400, 'The file already exists.')
@@ -347,7 +347,7 @@  discard block
 block discarded – undo
347 347
 	 */
348 348
 	public function testGetPaperHiveDocument($dir, $bookID, $correctDiscussions, $correctDocument, $expectedStatus, $expectedMessage) {
349 349
 		$title = "Borderland City in New India";
350
-		$path = $dir . '/'. $title. '.rev'.$bookID.'.paperhive';
350
+		$path = $dir . '/' . $title . '.rev' . $bookID . '.paperhive';
351 351
 		$contents = $this->fakeAll($bookID, $title);
352 352
 
353 353
 		if ($expectedStatus === 200) {
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
 			$this->assertArrayHasKey('extension', $data);
372 372
 			$this->assertArrayHasKey('discussionCount', $data);
373 373
 			$this->assertSame(2, $data['discussionCount']);
374
-			$this->assertSame('.rev'.$bookID.'.paperhive', $data['extension']);
374
+			$this->assertSame('.rev' . $bookID . '.paperhive', $data['extension']);
375 375
 		} else {
376 376
 			$this->assertArrayHasKey('message', $data);
377 377
 			$this->assertSame($expectedMessage, $data['message']);
Please login to merge, or discard this patch.