Passed
Push — master ( 6b97f6...a6ae80 )
by Blizzz
13:11 queued 11s
created

DirectEditingViewController::edit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * @copyright Copyright (c) 2019 Julius Härtl <[email protected]>
4
 *
5
 * @author Julius Härtl <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 * This program is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU Affero General Public License as
11
 * published by the Free Software Foundation, either version 3 of the
12
 * License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
 * GNU Affero General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Affero General Public License
20
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Files\Controller;
25
26
27
use Exception;
28
use OCP\AppFramework\Controller;
29
use OCP\AppFramework\Http\NotFoundResponse;
30
use OCP\AppFramework\Http\Response;
31
use OCP\DirectEditing\IManager;
32
use OCP\DirectEditing\RegisterDirectEditorEvent;
33
use OCP\EventDispatcher\IEventDispatcher;
34
use OCP\ILogger;
35
use OCP\IRequest;
36
37
class DirectEditingViewController extends Controller {
38
39
	/** @var IEventDispatcher */
40
	private $eventDispatcher;
41
42
	/** @var IManager */
43
	private $directEditingManager;
44
45
	/** @var ILogger */
46
	private $logger;
47
48
	public function __construct($appName, IRequest $request, IEventDispatcher $eventDispatcher, IManager $manager, ILogger $logger) {
49
		parent::__construct($appName, $request);
50
51
		$this->eventDispatcher = $eventDispatcher;
52
		$this->directEditingManager = $manager;
53
		$this->logger = $logger;
54
	}
55
56
	/**
57
	 * @PublicPage
58
	 * @NoCSRFRequired
59
	 *
60
	 * @param string $token
61
	 * @return Response
62
	 */
63
	public function edit(string $token): Response {
64
		$this->eventDispatcher->dispatchTyped(new RegisterDirectEditorEvent($this->directEditingManager));
65
		try {
66
			return $this->directEditingManager->edit($token);
67
		} catch (Exception $e) {
68
			$this->logger->logException($e);
69
			return new NotFoundResponse();
70
		}
71
	}
72
}
73