Passed
Push — master ( c4d71c...15ef35 )
by Morris
13:37 queued 11s
created

VersionHome::getUser()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright 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
24
namespace OCA\Files_Versions\Sabre;
25
26
use OC\User\NoUserException;
27
use OCA\Files_Versions\Versions\IVersionManager;
28
use OCP\Files\IRootFolder;
29
use OCP\IUserManager;
30
use Sabre\DAV\Exception\Forbidden;
31
use Sabre\DAV\ICollection;
32
33
class VersionHome implements ICollection {
34
35
	/** @var array */
36
	private $principalInfo;
37
38
	/** @var IRootFolder */
39
	private $rootFolder;
40
41
	/** @var IUserManager */
42
	private $userManager;
43
44
	/** @var IVersionManager */
45
	private $versionManager;
46
47
	public function __construct(array $principalInfo, IRootFolder $rootFolder, IUserManager $userManager, IVersionManager $versionManager) {
48
		$this->principalInfo = $principalInfo;
49
		$this->rootFolder = $rootFolder;
50
		$this->userManager = $userManager;
51
		$this->versionManager = $versionManager;
52
	}
53
54
	private function getUser() {
55
		list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']);
56
		$user = $this->userManager->get($name);
57
		if (!$user) {
58
			throw new NoUserException();
59
		}
60
	}
61
62
	public function delete() {
63
		throw new Forbidden();
64
	}
65
66
	public function getName(): string {
67
		return $this->getUser()->getUID();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->getUser() targeting OCA\Files_Versions\Sabre\VersionHome::getUser() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
68
	}
69
70
	public function setName($name) {
71
		throw new Forbidden();
72
	}
73
74
	public function createFile($name, $data = null) {
75
		throw new Forbidden();
76
	}
77
78
	public function createDirectory($name) {
79
		throw new Forbidden();
80
	}
81
82
	public function getChild($name) {
83
		$user = $this->getUser();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $user is correct as $this->getUser() targeting OCA\Files_Versions\Sabre\VersionHome::getUser() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
84
85
		if ($name === 'versions') {
86
			return new VersionRoot($user, $this->rootFolder, $this->versionManager);
0 ignored issues
show
Bug introduced by
$user of type null is incompatible with the type OCP\IUser expected by parameter $user of OCA\Files_Versions\Sabre...sionRoot::__construct(). ( Ignorable by Annotation )

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

86
			return new VersionRoot(/** @scrutinizer ignore-type */ $user, $this->rootFolder, $this->versionManager);
Loading history...
87
		}
88
		if ($name === 'restore') {
89
			return new RestoreFolder();
90
		}
91
	}
92
93
	public function getChildren() {
94
		$user = $this->getUser();
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $user is correct as $this->getUser() targeting OCA\Files_Versions\Sabre\VersionHome::getUser() seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
95
96
		return [
97
			new VersionRoot($user, $this->rootFolder, $this->versionManager),
0 ignored issues
show
Bug introduced by
$user of type null is incompatible with the type OCP\IUser expected by parameter $user of OCA\Files_Versions\Sabre...sionRoot::__construct(). ( Ignorable by Annotation )

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

97
			new VersionRoot(/** @scrutinizer ignore-type */ $user, $this->rootFolder, $this->versionManager),
Loading history...
98
			new RestoreFolder(),
99
		];
100
	}
101
102
	public function childExists($name) {
103
		return $name === 'versions' || $name === 'restore';
104
	}
105
106
	public function getLastModified() {
107
		return 0;
108
	}
109
}
110