Completed
Push — master ( 38df29...afa4ca )
by
unknown
7s
created

OccRunner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 27.78%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 37
ccs 5
cts 18
cp 0.2778
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 12 2
A runJson() 0 8 2
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\Exception\ProcessFailedException;
26
use Owncloud\Updater\Utils\Locator;
27
28
class OccRunner {
29
	/**
30
	 * @var Locator $locator
31
	 */
32
	protected $locator;
33
34
	/**
35
	 *
36
	 * @param Locator $locator
37
	 */
38
	public function __construct(Locator $locator){
39
		$this->locator = $locator;
40
	}
41
42
	public function run($args){
43
		$occPath = $this->locator->getPathToOccFile();
44
		$cmd = "php $occPath --no-warnings $args";
45
		$process = new Process($cmd);
46
		$process->setTimeout(null);
47
		$process->run();
48
49
		if (!$process->isSuccessful()){
50
			throw new ProcessFailedException($process);
51
		}
52
		return $process->getOutput();
53
	}
54
55 3
	public function runJson($args){
56 3
		$plain = $this->run($args . '  --output "json"');
57 3
		$decoded = json_decode($plain, true);
58 3
		if (!is_array($decoded)){
59
			throw new \UnexpectedValueException('Could not parse a response for ' . $args . '. Please check if the current shell user can run occ command. Raw output: ' . PHP_EOL . $plain);
60
		}
61 3
		return $decoded;
62
	}
63
64
}
65