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

InputMerger   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 2
dl 0
loc 28
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A merge() 0 12 3
A getKeysOfNullValues() 0 4 1
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
}