Completed
Push — stable9 ( 485cb1...e094cf )
by Lukas
26:41 queued 26:23
created

Expire::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 0
dl 11
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (c) 2016, ownCloud, Inc.
4
 *
5
 * @author Joas Schilling <[email protected]>
6
 * @author Morris Jobke <[email protected]>
7
 * @author Robin Appelman <[email protected]>
8
 *
9
 * @license AGPL-3.0
10
 *
11
 * This code is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License, version 3,
13
 * as published by the Free Software Foundation.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
 * GNU Affero General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU Affero General Public License, version 3,
21
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
22
 *
23
 */
24
25
namespace OCA\Files_Versions\Command;
26
27
use OC\Command\FileAccess;
28
use OCA\Files_Versions\Storage;
29
use OCP\Command\ICommand;
30
31 View Code Duplication
class Expire implements ICommand {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32
	use FileAccess;
33
34
	/**
35
	 * @var string
36
	 */
37
	private $fileName;
38
39
	/**
40
	 * @var string
41
	 */
42
	private $user;
43
44
	/**
45
	 * @param string $user
46
	 * @param string $fileName
47
	 */
48
	function __construct($user, $fileName) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
49
		$this->user = $user;
50
		$this->fileName = $fileName;
51
	}
52
53
54
	public function handle() {
55
		$userManager = \OC::$server->getUserManager();
56
		if (!$userManager->userExists($this->user)) {
57
			// User has been deleted already
58
			return;
59
		}
60
61
		\OC_Util::setupFS($this->user);
62
		Storage::expire($this->fileName);
63
		\OC_Util::tearDownFS();
64
	}
65
}
66