Completed
Pull Request — master (#217)
by Thomas
02:42
created

BzipExtractor   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 23.33 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 7
loc 30
ccs 0
cts 20
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A extract() 0 6 2
A extractShell() 7 7 1
A extractArchive() 0 3 1

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
 * @author Victor Dubiniuk <[email protected]>
4
 *
5
 * @copyright Copyright (c) 2015, ownCloud, Inc.
6
 * @license AGPL-3.0
7
 *
8
 * This code is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Affero General Public License, version 3,
10
 * as published by the Free Software Foundation.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU Affero General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Affero General Public License, version 3,
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
19
 *
20
 */
21
22
namespace Owncloud\Updater\Utils;
23
24
use Symfony\Component\Process\Process;
25
use Symfony\Component\Process\ProcessUtils;
26
27
class BzipExtractor {
28
29
	protected $file;
30
	protected $path;
31
32
	public function __construct($file, $path){
33
		$this->file = $file;
34
		$this->path = $path;
35
	}
36
37
	public function extract(){
38
		if ($this->extractShell()){
39
			return true;
40
		}
41
		return $this->extractArchive();
42
	}
43
44 View Code Duplication
	private function extractShell(){
0 ignored issues
show
Duplication introduced by
This method 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...
45
		$command = 'tar -jxvf  ' . ProcessUtils::escapeArgument($this->file) . ' -C ' . ProcessUtils::escapeArgument($this->path) . ' && chmod -R u+w ' . ProcessUtils::escapeArgument($this->path);
46
		$process = new Process($command);
47
		$process->run();
48
		echo $process->getErrorOutput();
49
		return $process->isSuccessful();
50
	}
51
52
	private function extractArchive(){
53
		throw new \RuntimeException("Could not decompress the archive, GNU tar is missing or shell_exec is disabled.");
54
	}
55
56
}
57