Completed
Pull Request — master (#31851)
by Thomas
19:39
created

JobStatus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 53
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 3

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getName() 0 3 1
A get() 0 7 2
A getETag() 0 3 1
A getSize() 0 3 1
A refreshStatus() 0 3 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\JobStatus as JobStatusEntity;
25
use OCA\DAV\JobStatus\Entity\JobStatusMapper;
26
use Sabre\DAV\File;
27
28
class JobStatus extends File {
29
30
	/** @var string */
31
	private $jobId;
32
	/** @var string */
33
	private $userId;
34
	/** @var string */
35
	private $data;
36
	/** @var JobStatusMapper */
37
	private $mapper;
38
	/** @var JobStatusEntity */
39
	private $entity;
40
41
	public function __construct($userId, $jobId,
42
								JobStatusMapper $mapper,
43
								JobStatusEntity $entity) {
44
		$this->userId = $userId;
45
		$this->jobId = $jobId;
46
		$this->mapper = $mapper;
47
		$this->entity = $entity;
48
	}
49
50
	/**
51
	 * Returns the name of the node.
52
	 *
53
	 * This is used to generate the url.
54
	 *
55
	 * @return string
56
	 */
57
	public function getName() {
58
		return $this->jobId;
59
	}
60
61
	public function get() {
62
		if ($this->entity === null) {
63
			$this->entity = $this->mapper
64
				->findByUserIdAndJobId($this->userId, $this->jobId);
65
		}
66
		return $this->entity->getStatusInfo();
67
	}
68
69
	public function getETag() {
70
		return '"' . \sha1($this->get()) . '"';
71
	}
72
73
	public function getSize() {
74
		return \strlen($this->get());
75
	}
76
77
	public function refreshStatus() {
78
		$this->entity = null;
79
	}
80
}
81