Completed
Pull Request — master (#26)
by Erwan
02:02 queued 39s
created

Merge::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * PHP Version 5.6
4
 * @category Library
5
 * @package ChangeLog
6
 * @author Erwan Richard <[email protected]>
7
 * @license MIT http://opensource.org/licenses/MIT
8
 * @link https://github.com/stevewest/changelog
9
 */
10
11
namespace ChangeLog\Console;
12
13
use ChangeLog\ChangeLog;
14
use ChangeLog\IO\File;
15
use ChangeLog\Parser\KeepAChangeLog;
16
use ChangeLog\Release as LogRelease;
17
use ChangeLog\Renderer\KeepAChangeLog as KeepAChangeLogRenderer;
18
use Symfony\Component\Console\Input\InputArgument;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Input\InputOption;
21
use Symfony\Component\Console\Output\OutputInterface;
22
23
/**
24
 * Converts a release between formats.
25
 */
26
class Merge extends AbstractCommand
27
{
28
	/**
29
	 * @return string
30
	 * @codeCoverageIgnore
31
	 */
32
	public function getDescription()
33
	{
34
		return 'Merge two or more changelog into one.';
35
	}
36
37 1
	protected function configure()
38
	{
39 1
		parent::configure();
40
41 1
		$this->addArgument(
42 1
			'files',
43 1
			InputArgument::IS_ARRAY,
44
			'Changelog to merge.'
45 1
		);
46 1
	}
47
48 1
	public function execute(InputInterface $input, OutputInterface $output)
49
	{
50 1
		parent::execute($input, $output);
51
52
		// Parse existing CHANGELOG
53 1
		$logs = $this->changeLog->parse();
54
55 1
		$files = $input->getArgument('files');
56 1
		foreach ($files as $f) {
0 ignored issues
show
Bug introduced by
The expression $files of type string|array<integer,string>|null is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
57
			// Merge each file
58 1
			$this->changeLog->setInput(new File(['file' => $f]));
59 1
			$logs->mergeLog($this->changeLog->parse());
60 1
		}
61
62
		// Write updated CHANGELOG
63 1
		$this->changeLog->write($logs);
64 1
	}
65
}
66