Completed
Pull Request — master (#78)
by Marcel
08:46 queued 31s
created

InputMerger::merge()   C

Complexity

Conditions 7
Paths 16

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 20
CRAP Score 7

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 24
ccs 20
cts 20
cp 1
rs 6.7272
cc 7
eloc 15
nc 16
nop 2
crap 7
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 2
	public function merge(InputInterface $input, Configuration $config)
21
	{
22 2
		foreach ($input->getArguments() as $argument => $value) {
23 2
			if ($input->hasArgumentSet($argument)) {
0 ignored issues
show
Bug introduced by
The method hasArgumentSet() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasArgument()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
24 1
				$config->set($argument, $value);
25 1
			} else {
26 2
				$configValue = $config->get($argument);
27 2
				if ($configValue !== null) {
28 1
					$input->setArgument($argument, $config->get($argument));
29 1
				}
30
			}
31 2
		}
32
33 2
		foreach ($input->getOptions() as $option => $value) {
34 2
			if ($input->hasOptionSet($option)) {
0 ignored issues
show
Bug introduced by
The method hasOptionSet() does not exist on Symfony\Component\Console\Input\InputInterface. Did you maybe mean hasOption()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
35 1
				$config->set($option, $value);
36 1
			} else {
37 2
				$configValue = $config->get($option);
38 2
				if ($configValue !== null) {
39 1
					$input->setOption($option, $configValue);
40 1
				}
41
			}
42 2
		}
43 2
	}
44
}
45