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

Token::getToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 2
rs 10
cc 1
nc 1
nop 0
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 OC\DirectEditing;
25
26
27
use OCP\DirectEditing\IToken;
28
use OCP\Files\File;
29
30
class Token implements IToken {
31
32
	/** @var Manager */
33
	private $manager;
34
	private $data;
35
36
	public function __construct(Manager $manager, $data) {
37
		$this->manager = $manager;
38
		$this->data = $data;
39
	}
40
41
	public function extend(): void {
42
		$this->manager->refreshToken($this->data['token']);
43
	}
44
45
	public function invalidate(): void {
46
		$this->manager->invalidateToken($this->data['token']);
47
	}
48
49
	public function getFile(): File {
50
		if ($this->data['share_id'] !== null) {
51
			return $this->manager->getShareForToken($this->data['share_id']);
0 ignored issues
show
Bug introduced by
The method getShareForToken() does not exist on OC\DirectEditing\Manager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
			return $this->manager->/** @scrutinizer ignore-call */ getShareForToken($this->data['share_id']);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
		}
53
		return $this->manager->getFileForToken($this->data['user_id'], $this->data['file_id']);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->manager->g...$this->data['file_id']) returns the type OCP\Files\Node which includes types incompatible with the type-hinted return OCP\Files\File.
Loading history...
54
	}
55
56
	public function getToken(): string {
57
		return $this->data['token'];
58
	}
59
60
	public function useTokenScope(): void {
61
		$this->manager->invokeTokenScope($this->data['user_id']);
62
	}
63
64
	public function hasBeenAccessed(): bool {
65
		return (bool) $this->data['accessed'];
66
	}
67
68
	public function getEditor(): string {
69
		return $this->data['editor_id'];
70
	}
71
72
	public function getUser(): string {
73
		return $this->data['user_id'];
74
	}
75
76
}
77