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

Expire   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 4 4 1
A handle() 11 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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