Completed
Push — master ( e5e771...ea902a )
by Thomas
02:47
created

OccRunner   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 3
dl 0
loc 34
ccs 5
cts 15
cp 0.3333
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A run() 0 9 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
		$process = new Process($this->locator->getPathToOccFile() . ' ' . $args);
44
		$process->run();
45
46
		if (!$process->isSuccessful()){
47
			throw new ProcessFailedException($process);
48
		}
49
		return $process->getOutput();
50
	}
51
52 3
	public function runJson($args){
53 3
		$plain = $this->run($args . '  --output "json"');
54 3
		$decoded = json_decode($plain, true);
55 3
		if (!is_array($decoded)){
56
			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);
57
		}
58 3
		return $decoded;
59
	}
60
61
}
62