ChangelogCommand::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
c 2
b 0
f 0
dl 0
loc 19
ccs 0
cts 12
cp 0
rs 9.9332
cc 2
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * This file is part of the SVN-Buddy library.
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 *
7
 * @copyright Alexander Obuhovich <[email protected]>
8
 * @link      https://github.com/console-helpers/svn-buddy
9
 */
10
11
namespace ConsoleHelpers\SVNBuddy\Command;
12
13
14
use Fiasco\SymfonyConsoleStyleMarkdown\Renderer;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
final class ChangelogCommand extends AbstractCommand
19
{
20
21
	/**
22
	 * {@inheritdoc}
23
	 */
24
	protected function configure()
25
	{
26
		$this
27
			->setName('changelog')
28
			->setDescription('Displays changes included in the current SVN-Buddy release');
29
30
		parent::configure();
31
	}
32
33
	protected function execute(InputInterface $input, OutputInterface $output)
34
	{
35
		$root_path = \dirname(__DIR__) . '/../..';
36
		$raw_changelog = \file_get_contents($root_path . '/CHANGELOG.md');
37
38
		$app_version = $this->getApplication()->getVersion();
39
40
		// Reassign all unreleased changes to current unstable version.
41
		if ( strpos($raw_changelog, $app_version) === false ) {
42
			$raw_changelog = str_replace(
43
				'[Unreleased]',
44
				'[' . $app_version . ']',
45
				$raw_changelog
46
			);
47
		}
48
49
		$markdown_renderer = Renderer::createFromMarkdown($raw_changelog);
50
51
		$this->io->writeln((string)$markdown_renderer);
52
	}
53
54
}
55