Completed
Push — master ( f37ab5...9ec323 )
by T
20:09
created

InputMerger::merge()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 11
cts 11
cp 1
rs 9.4285
cc 3
eloc 8
nc 4
nop 2
crap 3
1
<?php
2
3
namespace PHPSemVerChecker\Console;
4
5
use PHPSemVerChecker\Configuration\Configuration;
6
use Symfony\Component\Console\Input\InputInterface;
7
8
/**
9
 * Merges CLI input with existing configuration values.
10
 *
11
 * This is to ensure that CLI input has priority and is prepared for validation
12
 * by symfony/console commands.
13
 */
14
class InputMerger
15
{
16
	/**
17
	 * @param \Symfony\Component\Console\Input\InputInterface $input
18
	 * @param \PHPSemVerChecker\Configuration\Configuration $config
19
	 */
20 1
	public function merge(InputInterface $input, Configuration $config)
21
	{
22 1
		$missingArguments = $this->getKeysOfNullValues($input->getArguments());
23 1
		foreach ($missingArguments as $key) {
24 1
			$input->setArgument($key, $config->get($key));
25 1
		}
26 1
		$missingOptions = $this->getKeysOfNullValues($input->getOptions());
27 1
		foreach ($missingOptions as $key) {
28 1
			$input->setOption($key, $config->get($key));
29 1
		}
30 1
		$config->merge(array_merge($input->getArguments(), $input->getOptions()));
31 1
	}
32
33
	/**
34
	 * @param array $array
35
	 * @return array
36
	 */
37 1
	private function getKeysOfNullValues(array $array)
38
	{
39 1
		return array_keys(array_filter($array, 'is_null'));
40
	}
41
}