Php   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
wmc 16
lcom 1
cbo 1
dl 0
loc 73
ccs 27
cts 39
cp 0.6923
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSettings() 0 4 1
A setSettings() 0 4 1
A execute() 0 17 4
B testSettings() 0 15 7
A testExtensions() 0 8 3
1
<?php
2
3
4
namespace Genesis\Commands\Test;
5
6
7
use Genesis\Commands\Command;
8
9
/**
10
 * @author Adam Bisek <[email protected]>
11
 */
12
class Php extends Command
13
{
14
15
	/** @var string[] */
16
	private $errors;
17
18
	private $settings;
19
20
21
	/**
22
	 * @return array
23
	 */
24
	public function getSettings()
25
	{
26
		return $this->settings;
27
	}
28
29
30
	/**
31
	 * @param array $settings
32
	 */
33 1
	public function setSettings($settings)
34
	{
35 1
		$this->settings = $settings;
36 1
	}
37
38
39 1
	public function execute()
40 1
	{
41 1
		$this->errors = [];
42
43 1
		if (isset($this->settings['settings'])) {
44 1
			$this->testSettings($this->settings['settings']);
45 1
		}
46 1
		if (isset($this->settings['extensions'])) {
47 1
			$this->testExtensions($this->settings['extensions']);
48 1
		}
49
50 1
		if (!empty($this->errors)) {
51
			$this->error(implode(PHP_EOL, $this->errors));
52
		}
53
54 1
		$this->log('PHP settings correct.');
55 1
	}
56
57
58 1
	private function testSettings(array $settings)
59
	{
60 1
		foreach ($settings as $option => $requiredValue) {
61 1
			$setValue = ini_get($option);
62 1
			if ($requiredValue === '0') {
63
				if ($setValue !== '' && $setValue && $setValue != $requiredValue) { // intentionally !=
64
					$this->errors[] = 'PHP option ' . $option . ' is not set to required value "' . $requiredValue . '".';
65
				}
66
			} else {
67 1
				if ($setValue != $requiredValue) { // intentionally
68
					$this->errors[] = 'PHP option ' . $option . ' is not set to required value "' . $requiredValue . '".';
69
				}
70
			}
71 1
		}
72 1
	}
73
74
75 1
	private function testExtensions(array $extensions)
76
	{
77 1
		foreach ($extensions as $extension) {
78 1
			if (!extension_loaded($extension)) {
79
				$this->errors[] = 'Required PHP extension "' . $extension . '" is not loaded.';
80
			}
81 1
		}
82 1
	}
83
84
}
85