Passed
Push — main ( b13b1c...30676d )
by Emlyn
12:24
created

Merge   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 40
ccs 16
cts 16
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 3 1
A configure() 0 8 1
A execute() 0 18 2
1
<?php
2
/**
3
 * @category Library
4
 * @license MIT http://opensource.org/licenses/MIT
5
 * @link https://github.com/emlynwest/changelog
6
 */
7
8
namespace ChangeLog\Console;
9
10
use ChangeLog\ChangeLog;
11
use ChangeLog\IO\File;
12
use ChangeLog\Parser\KeepAChangeLog;
13
use ChangeLog\Release as LogRelease;
14
use ChangeLog\Renderer\KeepAChangeLog as KeepAChangeLogRenderer;
15
use Symfony\Component\Console\Command\Command;
16
use Symfony\Component\Console\Input\InputArgument;
17
use Symfony\Component\Console\Input\InputInterface;
18
use Symfony\Component\Console\Input\InputOption;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
/**
22
 * Converts a release between formats.
23
 */
24
class Merge extends AbstractCommand
25
{
26
	/**
27
	 * @return string
28
	 * @codeCoverageIgnore
29
	 */
30
	public function getDescription(): string
31
	{
32
		return 'Merge two or more changelog into one.';
33
	}
34
35 1
	protected function configure()
36
	{
37 1
		parent::configure();
38
39 1
		$this->addArgument(
40 1
			'files',
41 1
			InputArgument::IS_ARRAY,
42 1
			'Changelog to merge.'
43 1
		);
44
	}
45
46 1
	public function execute(InputInterface $input, OutputInterface $output): int
47
	{
48 1
		parent::execute($input, $output);
49
50
		// Parse existing CHANGELOG
51 1
		$logs = $this->changeLog->parse();
52
53 1
		$files = $input->getArgument('files');
54 1
		foreach ($files as $f) {
55
			// Merge each file
56 1
			$this->changeLog->setInput(new File(['file' => $f]));
57 1
			$logs->mergeLog($this->changeLog->parse());
58
		}
59
60
		// Write updated CHANGELOG
61 1
		$this->changeLog->write($logs);
62
63 1
		return Command::SUCCESS;
64
	}
65
}
66