Failed Conditions
Push — master ( 9e0fbd...284e4a )
by Alexander
01:54
created

BackwardsCompatibilityCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 18
ccs 0
cts 18
cp 0
rs 9.4285
c 1
b 0
f 0
cc 1
eloc 14
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of the Code-Insight 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/code-insight
9
 */
10
11
namespace ConsoleHelpers\CodeInsight\Command;
12
13
14
use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory;
15
use Symfony\Component\Console\Input\InputArgument;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Output\OutputInterface;
18
19
class BackwardsCompatibilityCommand extends AbstractCommand
20
{
21
22
	/**
23
	 * Knowledge base factory.
24
	 *
25
	 * @var KnowledgeBaseFactory
26
	 */
27
	private $_knowledgeBaseFactory;
28
29
	/**
30
	 * {@inheritdoc}
31
	 */
32
	protected function configure()
33
	{
34
		$this
35
			->setName('backwards-compatibility')
36
			->setAliases(array('bc'))
37
			->setDescription('Detects backwards compatibility breaks between 2 project versions')
38
			->addArgument(
39
				'source-project-path',
40
				InputArgument::REQUIRED,
41
				'Path to source project root folder (where <comment>.code-insight.json</comment> is located)'
42
			)
43
			->addArgument(
44
				'target-project-path',
45
				InputArgument::OPTIONAL,
46
				'Path to target project root folder (where <comment>.code-insight.json</comment> is located)',
47
				'.'
48
			);
49
	}
50
51
	/**
52
	 * Prepare dependencies.
53
	 *
54
	 * @return void
55
	 */
56
	protected function prepareDependencies()
57
	{
58
		parent::prepareDependencies();
59
60
		$container = $this->getContainer();
61
62
		$this->_knowledgeBaseFactory = $container['knowledge_base_factory'];
63
	}
64
65
	/**
66
	 * {@inheritdoc}
67
	 */
68
	protected function execute(InputInterface $input, OutputInterface $output)
69
	{
70
		$source_knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase(
71
			$this->getPath('source-project-path'),
72
			$this->io
73
		);
74
		$target_knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase(
75
			$this->getPath('target-project-path'),
76
			$this->io
77
		);
78
79
		$bc_breaks = $target_knowledge_base->getBackwardsCompatibilityBreaks($source_knowledge_base->getDatabase());
80
81
		if ( !$bc_breaks ) {
1 ignored issue
show
Bug Best Practice introduced by
The expression $bc_breaks of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
82
			$this->io->writeln('No backwards compatibility breaks detected.');
83
84
			return;
85
		}
86
87
		$this->io->writeln('Backward compatibility breaks:');
88
89
		foreach ( $bc_breaks as $bc_break => $incidents ) {
90
			$this->io->writeln('<fg=red>=== ' . $bc_break . ' ===</>');
91
92
			foreach ( $incidents as $incident ) {
93
				$incident = implode(PHP_EOL . '   ', explode(PHP_EOL, $incident));
94
95
				$this->io->writeln(' * ' . $incident);
96
			}
97
98
			$this->io->writeln('');
99
		}
100
	}
101
102
}
103