CompareCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 12

Test Coverage

Coverage 28.57%

Importance

Changes 0
Metric Value
wmc 3
lcom 2
cbo 12
dl 0
loc 76
ccs 14
cts 49
cp 0.2857
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 17 1
A execute() 0 48 2
1
<?php
2
3
namespace PHPSemVerChecker\Console\Command;
4
5
use PHPSemVerChecker\Analyzer\Analyzer;
6
use PHPSemVerChecker\Filter\SourceFilter;
7
use PHPSemVerChecker\Finder\Finder;
8
use PHPSemVerChecker\Reporter\JsonReporter;
9
use PHPSemVerChecker\Reporter\Reporter;
10
use PHPSemVerChecker\Scanner\ProgressScanner;
11
use PHPSemVerChecker\Scanner\Scanner;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
use Symfony\Component\Console\Input\InputOption;
15
use Symfony\Component\Console\Output\OutputInterface;
16
17
class CompareCommand extends BaseCommand
18
{
19
	/**
20
	 * @return void
21
	 */
22 1
	protected function configure()
23
	{
24
		$this
25 1
			->setName('compare')
26 1
			->setDescription('Compare a set of files to determine what semantic versioning change needs to be done')
27 1
			->setDefinition([
28 1
				new InputArgument('source-before', InputArgument::REQUIRED, 'A base directory to check (ex my-test)'),
29 1
				new InputArgument('source-after', InputArgument::REQUIRED, 'A base directory to check against (ex my-test)'),
30 1
				new InputOption('include-before', null, InputOption::VALUE_REQUIRED, 'List of paths to include <info>(comma separated)</info>'),
31 1
				new InputOption('include-after', null, InputOption::VALUE_REQUIRED, 'List of paths to include <info>(comma separated)</info>'),
32 1
				new InputOption('exclude-before', null, InputOption::VALUE_REQUIRED, 'List of paths to exclude <info>(comma separated)</info>'),
33 1
				new InputOption('exclude-after', null, InputOption::VALUE_REQUIRED, 'List of paths to exclude <info>(comma separated)</info>'),
34 1
				new InputOption('full-path', null, InputOption::VALUE_NONE, 'Display the full path to the file instead of the relative path'),
35 1
				new InputOption('config', null, InputOption::VALUE_REQUIRED, 'A configuration file to configure php-semver-checker'),
36 1
				new InputOption('to-json', null, InputOption::VALUE_REQUIRED, 'Output the result to a JSON file')
37
			]);
38 1
	}
39
40
	/**
41
	 * @param \Symfony\Component\Console\Input\InputInterface   $input
42
	 * @param \Symfony\Component\Console\Output\OutputInterface $output
43
	 */
44
	protected function execute(InputInterface $input, OutputInterface $output)
45
	{
46
		$startTime = microtime(true);
47
48
		$finder = new Finder();
49
		$scannerBefore = new Scanner();
50
		$scannerAfter = new Scanner();
51
52
		$sourceBefore = $this->config->get('source-before');
53
		$includeBefore = $this->config->get('include-before');
54
		$excludeBefore = $this->config->get('exclude-before');
55
56
		$sourceAfter = $this->config->get('source-after');
57
		$includeAfter = $this->config->get('include-after');
58
		$excludeAfter = $this->config->get('exclude-after');
59
60
		$sourceBefore = $finder->findFromString($sourceBefore, $includeBefore, $excludeBefore);
61
		$sourceAfter = $finder->findFromString($sourceAfter, $includeAfter, $excludeAfter);
62
63
		$sourceFilter = new SourceFilter();
64
		$identicalCount = $sourceFilter->filter($sourceBefore, $sourceAfter);
65
66
		$progress = new ProgressScanner($output);
67
		$progress->addJob($this->config->get('source-before'), $sourceBefore, $scannerBefore);
68
		$progress->addJob($this->config->get('source-after'), $sourceAfter, $scannerAfter);
69
		$progress->runJobs();
70
71
		$registryBefore = $scannerBefore->getRegistry();
72
		$registryAfter = $scannerAfter->getRegistry();
73
74
		$analyzer = new Analyzer();
75
		$report = $analyzer->analyze($registryBefore, $registryAfter);
76
77
		$reporter = new Reporter($report);
78
		$reporter->setFullPath($this->config->get('full-path'));
79
		$reporter->output($output);
80
81
		$toJson = $this->config->get('to-json');
82
		if ($toJson) {
83
			$jsonReporter = new JsonReporter($report, $toJson);
84
			$jsonReporter->output();
85
		}
86
87
		$duration = microtime(true) - $startTime;
88
		$output->writeln('');
89
		$output->writeln('[Scanned files] Before: ' . count($sourceBefore) . ', After: ' . count($sourceAfter) . ', Identical: ' . $identicalCount);
90
		$output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB');
91
	}
92
}
93