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

Merge::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
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