Completed
Push — master ( 4d412b...c0b425 )
by Morris
11s
created

OCSController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 60
ccs 0
cts 33
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A create() 0 27 4
1
<?php
2
/**
3
 * @copyright Copyright (c) 2018, Roeland Jago Douma <[email protected]>
4
 *
5
 * @author Roeland Jago Douma <[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
namespace OCA\Richdocuments\Controller;
24
25
use OCA\Richdocuments\Db\DirectMapper;
26
use OCP\AppFramework\Http\DataResponse;
27
use OCP\AppFramework\OCS\OCSBadRequestException;
28
use OCP\AppFramework\OCS\OCSNotFoundException;
29
use OCP\Files\Folder;
30
use OCP\Files\IRootFolder;
31
use OCP\Files\NotFoundException;
32
use OCP\IRequest;
33
use OCP\IURLGenerator;
34
35
class OCSController extends \OCP\AppFramework\OCSController {
36
	/** @var IRootFolder */
37
	private $rootFolder;
38
39
	/** @var string */
40
	private $userId;
41
42
	/** @var DirectMapper */
43
	private $directMapper;
44
45
	/** @var IURLGenerator */
46
	private $urlGenerator;
47
48
	public function __construct($appName,
49
								IRequest $request,
50
								IRootFolder $rootFolder,
51
								$userId,
52
								DirectMapper $directMapper,
53
								IURLGenerator $urlGenerator) {
54
		parent::__construct($appName, $request);
55
56
		$this->rootFolder = $rootFolder;
57
		$this->userId = $userId;
58
		$this->directMapper = $directMapper;
59
		$this->urlGenerator = $urlGenerator;
60
	}
61
62
	/**
63
	 * @NoAdminRequired
64
	 *
65
	 * @param int $fileId
66
	 */
67
	public function create($fileId) {
68
		try {
69
			$userFolder = $this->rootFolder->getUserFolder($this->userId);
70
			$nodes = $userFolder->getById($fileId);
71
72
			if ($nodes === []) {
73
				throw new NotFoundException();
74
			}
75
76
			$node = $nodes[0];
77
			if ($node instanceof Folder) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\Folder does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
78
				throw new OCSBadRequestException('Cannot view folder');
79
			}
80
81
			//TODO check if we can even edit this file with collabora
82
			
83
			$direct = $this->directMapper->newDirect($this->userId, $fileId);
84
85
			return new DataResponse([
86
				'url' => $this->urlGenerator->linkToRouteAbsolute('richdocuments.directView.show', [
87
					'token' => $direct->getToken()
88
				])
89
			]);
90
		} catch (NotFoundException $e) {
0 ignored issues
show
Bug introduced by
The class OCP\Files\NotFoundException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
91
			throw new OCSNotFoundException();
92
		}
93
	}
94
}
95