Completed
Pull Request — master (#26700)
by Philipp
08:19
created

apps/files_external/lib/Lib/PersonalMount.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * @author Morris Jobke <[email protected]>
4
 * @author Robin Appelman <[email protected]>
5
 * @author Robin McCorkell <[email protected]>
6
 *
7
 * @copyright Copyright (c) 2016, ownCloud GmbH.
8
 * @license AGPL-3.0
9
 *
10
 * This code is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Affero General Public License, version 3,
12
 * as published by the Free Software Foundation.
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, version 3,
20
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
21
 *
22
 */
23
24
namespace OCA\Files_External\Lib;
25
26
use OC\Files\Mount\MountPoint;
27
use OC\Files\Mount\MoveableMount;
28
use OCA\Files_External\Service\UserStoragesService;
29
30
/**
31
 * Person mount points can be moved by the user
32
 */
33
class PersonalMount extends MountPoint implements MoveableMount {
34
	/** @var UserStoragesService */
35
	protected $storagesService;
36
37
	/** @var int */
38
	protected $numericStorageId;
39
40
	/**
41
	 * @param UserStoragesService $storagesService
42
	 * @param int $storageId
43
	 * @param \OCP\Files\Storage $storage
44
	 * @param string $mountpoint
45
	 * @param array $arguments (optional) configuration for the storage backend
46
	 * @param \OCP\Files\Storage\IStorageFactory $loader
47
	 * @param array $mountOptions mount specific options
48
	 */
49
	public function __construct(
50
		UserStoragesService $storagesService,
51
		$storageId,
52
		$storage,
53
		$mountpoint,
54
		$arguments = null,
55
		$loader = null,
56
		$mountOptions = null
57
	) {
58
		parent::__construct($storage, $mountpoint, $arguments, $loader, $mountOptions);
59
		$this->storagesService = $storagesService;
60
		$this->numericStorageId = $storageId;
61
	}
62
63
	/**
64
	 * Move the mount point to $target
65
	 *
66
	 * @param string $target the target mount point
67
	 * @return bool
68
	 */
69
	public function moveMount($target) {
70
		$storage = $this->storagesService->getStorage($this->numericStorageId);
71
		// remove "/$user/files" prefix
72
		$targetParts = explode('/', trim($target, '/'), 3);
73
		$storage->setMountPoint($targetParts[2]);
74
		$this->storagesService->updateStorage($storage);
0 ignored issues
show
It seems like $storage defined by $this->storagesService->...this->numericStorageId) on line 70 can be null; however, OCA\Files_External\Servi...ervice::updateStorage() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
75
		$this->setMountPoint($target);
76
		return true;
77
	}
78
79
	/**
80
	 * Remove the mount points
81
	 *
82
	 * @return bool
83
	 */
84
	public function removeMount() {
85
		$this->storagesService->removeStorage($this->numericStorageId);
86
		return true;
87
	}
88
}
89