NodeJs::execute()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.0884

Importance

Changes 0
Metric Value
dl 0
loc 17
ccs 11
cts 14
cp 0.7856
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 4
nop 0
crap 3.0884
1
<?php
2
3
4
namespace Genesis\Commands\Test;
5
6
7
use Genesis\Commands;
8
use Genesis\Commands\Command;
9
10
/**
11
 * @author Adam Bisek <[email protected]>
12
 */
13
class NodeJs extends Command
14
{
15
16
	private $nodeVersionCommand = 'node -v';
17
18
	private $requiredVersion;
19
20
21
	/**
22
	 * @return float
23
	 */
24
	public function getRequiredVersion()
25
	{
26
		return $this->requiredVersion;
27
	}
28
29
30
	/**
31
	 * @param float $requiredVersion
32
	 */
33 2
	public function setRequiredVersion($requiredVersion)
34
	{
35 2
		$this->requiredVersion = $requiredVersion;
36 2
	}
37
38
39 2
	public function execute()
40
	{
41 2
		$cmd = $this->nodeVersionCommand;
42 2
		$command = new Commands\Exec();
43 2
		$command->setCommand($cmd);
44 2
		$result = $command->execute();
45 2
		if ($result->getResult() !== 0) {
46
			$this->error(sprintf('Execution of command "%s" failed.', $cmd));
47
		}
48
49 2
		$version = $result->getOutput()[0];
50 2
		if (version_compare($version, $this->requiredVersion) < 0) {
51 1
			$this->error(sprintf('Node.JS is not current. Version %s required, but %s is installed.', $this->requiredVersion, $version));
52
		}
53
54 1
		$this->log(sprintf('Required Node.JS version %s satisfied with installed version %s.', $this->requiredVersion, $version));
55 1
	}
56
57
}
58