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