Completed
Push — master ( 65e3b0...b26a8a )
by
unknown
31:46 queued 19:29
created

Home   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getChild() 0 9 2
A getChildren() 0 3 1
A getName() 0 4 1
1
<?php
2
/**
3
 * @author Thomas Müller <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2018, ownCloud GmbH
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
namespace OCA\DAV\JobStatus;
22
23
use OCA\DAV\DAV\LazyOpsPlugin;
24
use OCA\DAV\JobStatus\Entity\JobStatusMapper;
25
use OCP\AppFramework\Db\DoesNotExistException;
26
use Sabre\DAV\Collection;
27
use Sabre\DAV\Exception\Forbidden;
28
use Sabre\DAV\Exception\MethodNotAllowed;
29
use Sabre\DAV\Exception\NotFound;
30
use Sabre\DAV\SimpleFile;
31
use Sabre\HTTP\URLUtil;
32
33
class Home extends Collection {
34
	/** @var array */
35
	private $principalInfo;
36
	/** @var JobStatusMapper */
37
	private $mapper;
38
39
	/**
40
	 * Home constructor.
41
	 *
42
	 * @param array $principalInfo
43
	 * @param JobStatusMapper $mapper
44
	 */
45
	public function __construct($principalInfo, JobStatusMapper $mapper) {
46
		$this->principalInfo = $principalInfo;
47
		$this->mapper = $mapper;
48
	}
49
50
	public function getChild($name) {
51
		try {
52
			$entity = $this->mapper->findByUserIdAndJobId($this->getName(), $name);
53
54
			return new JobStatus($this->getName(), $name, $this->mapper, $entity);
55
		} catch (DoesNotExistException $ex) {
56
			throw new NotFound();
57
		}
58
	}
59
60
	public function getChildren() {
61
		throw new MethodNotAllowed('Listing members of this collection is disabled');
62
	}
63
64
	public function getName() {
65
		list(, $name) = URLUtil::splitPath($this->principalInfo['uri']);
66
		return $name;
67
	}
68
}
69