NodeJs   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 73.68%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 45
ccs 14
cts 19
cp 0.7368
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequiredVersion() 0 4 1
A setRequiredVersion() 0 4 1
A execute() 0 17 3
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