PackageInstaller   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 82.61%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 63
ccs 19
cts 23
cp 0.8261
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDirectory() 0 4 1
A setDirectory() 0 4 1
A getOptions() 0 4 1
A setOptions() 0 4 1
A execute() 0 15 4
1
<?php
2
3
namespace Genesis\Commands\NodeJs;
4
5
use Genesis\Commands\Command;
6
use Genesis\Commands\Exec;
7
8
9
/**
10
 * @author Adam Bisek <[email protected]>
11
 */
12
class PackageInstaller extends Command
13
{
14
15
	private $directory;
16
17
	private $options;
18
19
20
	/**
21
	 * Gets working directory.
22
	 * @return string
23
	 */
24
	public function getDirectory()
25
	{
26
		return $this->directory;
27
	}
28
29
30
	/**
31
	 * Sets working directory. System will switch to this directory before running npm.
32
	 * @param string $directory
33
	 */
34 2
	public function setDirectory($directory)
35
	{
36 2
		$this->directory = $directory;
37 2
	}
38
39
40
	/**
41
	 * @return array|NULL
42
	 */
43 2
	public function getOptions()
44
	{
45 2
		return $this->options;
46
	}
47
48
49
	/**
50
	 * @param array|NULL $options
51
	 */
52 2
	public function setOptions(array $options = NULL)
53
	{
54 2
		$this->options = $options;
55 2
	}
56
57
58 2
	public function execute()
59
	{
60 2
		$cmd = 'cd ' . escapeshellarg($this->directory) . ' && npm install';
61 2
		if (isset($this->options['silent']) && $this->options['silent']) {
62 2
			$cmd .= ' --silent'; // supress warnings
63 2
		}
64 2
		$command = new Exec();
65 2
		$command->setCommand($cmd);
66 2
		$result = $command->execute();
67 2
		if ($result->getResult() !== 0) {
68
			$this->error(sprintf('Installation of node modules for package in dir "%s" failed.', $this->directory));
69
		}
70 2
		$this->log("Npm installed modules successfully.");
71 2
		return $result;
72
	}
73
74
}