From e42dc8247cfba5c45a4613bdafe1a1310064d057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 22:26:35 +0100 Subject: [PATCH 01/16] splitting execute method --- .../Console/Command/SuggestCommand.php | 92 ++++++++++++------- 1 file changed, 57 insertions(+), 35 deletions(-) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index eeb5478..8132f2e 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -48,7 +48,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $startTime = microtime(true); $targetDirectory = getcwd(); - $tag = $this->config->get('tag'); $against = $this->config->get('against') ?: 'HEAD'; $includeBefore = $this->config->get('include-before'); @@ -61,11 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $repository = $client->getRepository($targetDirectory); - if ($tag === null) { - $tag = $this->findLatestTag($repository); - } else { - $tag = $this->findTag($repository, $tag); - } + $tag = $this->getInitialTag($repository); if ($tag === null) { $output->writeln('No tags to suggest against'); @@ -98,13 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $sourceAfter = $finder->findFromString($targetDirectory, $includeAfter, $excludeAfter); $sourceAfterMatchedCount = count($sourceAfter); $sourceAfter = $sourceFilter->filter($sourceAfter, $modifiedFiles); - $progress = new ProgressBar($output, count($sourceAfter)); - foreach ($sourceAfter as $file) { - $afterScanner->scan($file); - $progress->advance(); - } - - $progress->clear(); + $this->scanFileList($afterScanner, $sourceAfter, $output); // Finish with the tag commit $repository->checkout($tag . ' --'); @@ -112,13 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $sourceBefore = $finder->findFromString($targetDirectory, $includeBefore, $excludeBefore); $sourceBeforeMatchedCount = count($sourceBefore); $sourceBefore = $sourceFilter->filter($sourceBefore, $modifiedFiles); - $progress = new ProgressBar($output, count($sourceBefore)); - foreach ($sourceBefore as $file) { - $beforeScanner->scan($file); - $progress->advance(); - } - - $progress->clear(); + $this->scanFileList($beforeScanner, $sourceBefore, $output); // Reset repository to initial branch if ($initialBranch) { @@ -132,21 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $report = $analyzer->analyze($registryBefore, $registryAfter); $tag = new SemanticVersion($tag); - $newTag = new SemanticVersion($tag); - - $suggestedLevel = $report->getSuggestedLevel(); - - if ($suggestedLevel !== Level::NONE) { - if ($newTag->getPrerelease()) { - $newTag->inc('prerelease'); - } else { - if ($newTag->getMajor() < 1 && $suggestedLevel === Level::MAJOR) { - $newTag->inc('minor'); - } else { - $newTag->inc(strtolower(Level::toString($suggestedLevel))); - } - } - } + $newTag = $this->getNextTag($report, $tag); $output->writeln(''); $output->writeln('Initial semantic version: ' . $tag . ''); @@ -163,6 +132,59 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB'); } + /** + * @param Scanner $scanner + * @param array $files + * @param OutputInterface $output + */ + private function scanFileList(Scanner &$scanner, array &$files, OutputInterface &$output) + { + $progress = new ProgressBar($output, count($files)); + foreach ($files as $file) { + $scanner->scan($file); + $progress->advance(); + } + $progress->clear(); + } + + /** + * @param Report $report + * @param version $tag + * @return SemanticVersion + * @throws \vierbergenlars\SemVer\LogicException + */ + private function getNextTag(Report $report, version $tag) + { + $newTag = new SemanticVersion($tag); + $suggestedLevel = $report->getSuggestedLevel(); + if ($suggestedLevel === Level::NONE) { + return $newTag; + } + if ($newTag->getPrerelease()) { + $newTag->inc('prerelease'); + return $newTag; + } + if ($newTag->getMajor() < 1 && $suggestedLevel === Level::MAJOR) { + $newTag->inc('minor'); + return $newTag; + } + $newTag->inc(strtolower(Level::toString($suggestedLevel))); + return $newTag; + } + + /** + * @param Repository $repository + * @return null|string + */ + private function getInitialTag(Repository $repository) + { + $tag = $this->config->get('tag'); + if ($tag === null) { + return $this->findLatestTag($repository); + } + return $this->findTag($repository, $tag); + } + /** * @param \Gitter\Repository $repository * @return string|null From 4cdd1e603ce545c2c0dcf97006e5a7b9872c3a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 22:45:03 +0100 Subject: [PATCH 02/16] reducing duplicate code by extracting it into methods --- bin/php-semver-checker-git | 33 +++------ .../Console/Command/SuggestCommand.php | 74 ++++++++++++++----- 2 files changed, 69 insertions(+), 38 deletions(-) diff --git a/bin/php-semver-checker-git b/bin/php-semver-checker-git index a91d1b5..353a978 100755 --- a/bin/php-semver-checker-git +++ b/bin/php-semver-checker-git @@ -1,28 +1,19 @@ #!/usr/bin/env php run(new PHPSemVerChecker\Console\InspectableArgvInput()); + exit(0); } } -if (!$found) { - die( - 'php-semver-checker-git requires to be installed through composer.'.PHP_EOL. - 'See http://getcomposer.org/download/'.PHP_EOL - ); -} - -ini_set('xdebug.max_nesting_level', 5000); - -$app = new PHPSemVerCheckerGit\Console\Application(); -$app->run(new PHPSemVerChecker\Console\InspectableArgvInput()); +die( + 'php-semver-checker-git requires to be installed through composer.'.PHP_EOL. + 'See http://getcomposer.org/download/'.PHP_EOL +); \ No newline at end of file diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 8132f2e..8bca6a1 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -86,23 +86,30 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('If you still wish to run against a detached HEAD, use --allow-detached.'); return -1; } - - // Start with the against commit - $repository->checkout($against . ' --'); - - $sourceAfter = $finder->findFromString($targetDirectory, $includeAfter, $excludeAfter); - $sourceAfterMatchedCount = count($sourceAfter); - $sourceAfter = $sourceFilter->filter($sourceAfter, $modifiedFiles); - $this->scanFileList($afterScanner, $sourceAfter, $output); - - // Finish with the tag commit - $repository->checkout($tag . ' --'); - - $sourceBefore = $finder->findFromString($targetDirectory, $includeBefore, $excludeBefore); - $sourceBeforeMatchedCount = count($sourceBefore); - $sourceBefore = $sourceFilter->filter($sourceBefore, $modifiedFiles); - $this->scanFileList($beforeScanner, $sourceBefore, $output); - + list($sourceAfterMatchedCount, $sourceAfter) = $this->processFileList( + $repository, + $against, + $output, + $finder, + $sourceFilter, + $afterScanner, + $targetDirectory, + $includeAfter, + $excludeAfter, + $modifiedFiles + ); + list($sourceBeforeMatchedCount, $sourceBefore) = $this->processFileList( + $repository, + $tag, + $output, + $finder, + $sourceFilter, + $beforeScanner, + $targetDirectory, + $includeBefore, + $excludeBefore, + $modifiedFiles + ); // Reset repository to initial branch if ($initialBranch) { $repository->checkout($initialBranch); @@ -132,6 +139,39 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB'); } + /** + * @param Repository $repository + * @param string $commitIdentifier + * @param OutputInterface $output + * @param Finder $finder + * @param SourceFilter $filter + * @param Scanner $scanner + * @param $targetDirectory + * @param $include + * @param $exclude + * @param $modifiedFiles + * @return array + */ + private function processFileList( + Repository &$repository, + $commitIdentifier, + OutputInterface &$output, + Finder &$finder, + SourceFilter &$filter, + Scanner &$scanner, + $targetDirectory, + $include, + $exclude, + $modifiedFiles + ) { + $repository->checkout($commitIdentifier . ' --'); + $source = $finder->findFromString($targetDirectory, $include, $exclude); + $count = count($source); + $source = $filter->filter($source, $modifiedFiles); + $this->scanFileList($scanner, $source, $output); + return array($count, $source); + } + /** * @param Scanner $scanner * @param array $files From 9183fb2253a53d180654274dfc56254dbf1bbd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:17:29 +0100 Subject: [PATCH 03/16] extracting source file list processing into a class of it's own --- .../Console/Command/SuggestCommand.php | 134 ++++++------------ .../SourceFileProcessor.php | 99 +++++++++++++ 2 files changed, 143 insertions(+), 90 deletions(-) create mode 100644 src/PHPSemVerCheckerGit/SourceFileProcessor.php diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 8bca6a1..637cfa5 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -10,8 +10,8 @@ use PHPSemVerChecker\Scanner\Scanner; use PHPSemVerChecker\SemanticVersioning\Level; use PHPSemVerCheckerGit\Filter\SourceFilter; +use PHPSemVerCheckerGit\SourceFileProcessor; use RuntimeException; -use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -39,6 +39,16 @@ protected function configure() ]); } + /** + * @param string $directory + * @return Repository + */ + private function getRepository($directory) + { + $client = new Client(); + return $client->getRepository($directory); + } + /** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output @@ -50,15 +60,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $targetDirectory = getcwd(); $against = $this->config->get('against') ?: 'HEAD'; - $includeBefore = $this->config->get('include-before'); - $excludeBefore = $this->config->get('exclude-before'); - - $includeAfter = $this->config->get('include-after'); - $excludeAfter = $this->config->get('exclude-after'); - - $client = new Client(); - - $repository = $client->getRepository($targetDirectory); + $repository = $this->getRepository($targetDirectory); $tag = $this->getInitialTag($repository); @@ -69,15 +71,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Testing ' . $against . ' against tag: ' . $tag . ''); - $finder = new Finder(); - $sourceFilter = new SourceFilter(); $beforeScanner = new Scanner(); $afterScanner = new Scanner(); - $modifiedFiles = $repository->getModifiedFiles($tag, $against); - $modifiedFiles = array_filter($modifiedFiles, function ($modifiedFile) { - return substr($modifiedFile, -4) === '.php'; - }); + $sourceFileProcessor = new SourceFileProcessor( + new SourceFilter(), + $repository, + $output, + new Finder(), + $targetDirectory, + $repository->getModifiedFiles($tag, $against) + ); $initialBranch = $repository->getCurrentBranch(); @@ -86,29 +90,17 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('If you still wish to run against a detached HEAD, use --allow-detached.'); return -1; } - list($sourceAfterMatchedCount, $sourceAfter) = $this->processFileList( - $repository, - $against, - $output, - $finder, - $sourceFilter, + list($sourceAfterMatchedCount, $sourceAfter) = $sourceFileProcessor->processFileList( $afterScanner, - $targetDirectory, - $includeAfter, - $excludeAfter, - $modifiedFiles + $against, + $this->config->get('include-after'), + $this->config->get('exclude-after') ); - list($sourceBeforeMatchedCount, $sourceBefore) = $this->processFileList( - $repository, - $tag, - $output, - $finder, - $sourceFilter, + list($sourceBeforeMatchedCount, $sourceBefore) = $sourceFileProcessor->processFileList( $beforeScanner, - $targetDirectory, - $includeBefore, - $excludeBefore, - $modifiedFiles + $tag, + $this->config->get('include-before'), + $this->config->get('exclude-before') ); // Reset repository to initial branch if ($initialBranch) { @@ -124,9 +116,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $tag = new SemanticVersion($tag); $newTag = $this->getNextTag($report, $tag); - $output->writeln(''); - $output->writeln('Initial semantic version: ' . $tag . ''); - $output->writeln('Suggested semantic version: ' . $newTag . ''); + $output->write( + array( + '', + 'Initial semantic version: ' . $tag . '', + 'Suggested semantic version: ' . $newTag . '' + ), + true + ); if ($this->config->get('details')) { $reporter = new Reporter($report); @@ -134,59 +131,16 @@ protected function execute(InputInterface $input, OutputInterface $output) } $duration = microtime(true) - $startTime; - $output->writeln(''); - $output->writeln('[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . ' unfiltered)'); - $output->writeln('Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB'); + $output->write( + array( + '', + '[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . ' unfiltered)', + 'Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB' + ), + true + ); } - /** - * @param Repository $repository - * @param string $commitIdentifier - * @param OutputInterface $output - * @param Finder $finder - * @param SourceFilter $filter - * @param Scanner $scanner - * @param $targetDirectory - * @param $include - * @param $exclude - * @param $modifiedFiles - * @return array - */ - private function processFileList( - Repository &$repository, - $commitIdentifier, - OutputInterface &$output, - Finder &$finder, - SourceFilter &$filter, - Scanner &$scanner, - $targetDirectory, - $include, - $exclude, - $modifiedFiles - ) { - $repository->checkout($commitIdentifier . ' --'); - $source = $finder->findFromString($targetDirectory, $include, $exclude); - $count = count($source); - $source = $filter->filter($source, $modifiedFiles); - $this->scanFileList($scanner, $source, $output); - return array($count, $source); - } - - /** - * @param Scanner $scanner - * @param array $files - * @param OutputInterface $output - */ - private function scanFileList(Scanner &$scanner, array &$files, OutputInterface &$output) - { - $progress = new ProgressBar($output, count($files)); - foreach ($files as $file) { - $scanner->scan($file); - $progress->advance(); - } - $progress->clear(); - } - /** * @param Report $report * @param version $tag diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php new file mode 100644 index 0000000..4f229dd --- /dev/null +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -0,0 +1,99 @@ +repository = $repository; + $this->output = $output; + $this->finder = $finder; + $this->directory = $directory; + $this->addModifiedFiles($modifiedFiles); + } + + /** + * @param string[] $modified + */ + private function addModifiedFiles(array $modified) { + foreach($modified as $file) { + if(substr($file, -4) === '.php') { + $this->modifiedFiles[] = $file; + } + } + } + + + /** + * @param Scanner $scanner + * @param string $commitIdentifier + * @param $include + * @param $exclude + * @return array + */ + public function processFileList( + Scanner &$scanner, + $commitIdentifier, + $include, + $exclude + ) { + $this->repository->checkout($commitIdentifier . ' --'); + $source = $this->finder->findFromString($this->directory, $include, $exclude); + $count = count($source); + $source = $this->filter->filter($source, $this->modifiedFiles); + $this->scanFileList($scanner, $source); + return array($count, $source); + } + + /** + * @param Scanner $scanner + * @param array $files + */ + private function scanFileList(Scanner &$scanner, array &$files) + { + $progress = new ProgressBar($this->output, count($files)); + foreach ($files as $file) { + $scanner->scan($file); + $progress->advance(); + } + $progress->clear(); + } + +} \ No newline at end of file From 46ce68250a506e08cffe9cacd5ae66548ec8009e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:33:16 +0100 Subject: [PATCH 04/16] removing variables, that are better provided by ProcessedFileList --- .../Console/Command/SuggestCommand.php | 18 ++---- src/PHPSemVerCheckerGit/ProcessedFileList.php | 59 +++++++++++++++++++ .../SourceFileProcessor.php | 22 +++---- 3 files changed, 73 insertions(+), 26 deletions(-) create mode 100644 src/PHPSemVerCheckerGit/ProcessedFileList.php diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 637cfa5..7c2bc59 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -7,7 +7,6 @@ use PHPSemVerChecker\Analyzer\Analyzer; use PHPSemVerChecker\Finder\Finder; use PHPSemVerChecker\Reporter\Reporter; -use PHPSemVerChecker\Scanner\Scanner; use PHPSemVerChecker\SemanticVersioning\Level; use PHPSemVerCheckerGit\Filter\SourceFilter; use PHPSemVerCheckerGit\SourceFileProcessor; @@ -52,6 +51,7 @@ private function getRepository($directory) /** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output + * @return void */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -71,9 +71,6 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('Testing ' . $against . ' against tag: ' . $tag . ''); - $beforeScanner = new Scanner(); - $afterScanner = new Scanner(); - $sourceFileProcessor = new SourceFileProcessor( new SourceFilter(), $repository, @@ -90,14 +87,12 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('If you still wish to run against a detached HEAD, use --allow-detached.'); return -1; } - list($sourceAfterMatchedCount, $sourceAfter) = $sourceFileProcessor->processFileList( - $afterScanner, + $after = $sourceFileProcessor->processFileList( $against, $this->config->get('include-after'), $this->config->get('exclude-after') ); - list($sourceBeforeMatchedCount, $sourceBefore) = $sourceFileProcessor->processFileList( - $beforeScanner, + $before = $sourceFileProcessor->processFileList( $tag, $this->config->get('include-before'), $this->config->get('exclude-before') @@ -107,11 +102,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $repository->checkout($initialBranch); } - $registryBefore = $beforeScanner->getRegistry(); - $registryAfter = $afterScanner->getRegistry(); - $analyzer = new Analyzer(); - $report = $analyzer->analyze($registryBefore, $registryAfter); + $report = $analyzer->analyze($before->getScanner()->getRegistry(), $after->getScanner()->getRegistry()); $tag = new SemanticVersion($tag); $newTag = $this->getNextTag($report, $tag); @@ -134,7 +126,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->write( array( '', - '[Scanned files] Before: ' . count($sourceBefore) . ' (' . $sourceBeforeMatchedCount . ' unfiltered), After: ' . count($sourceAfter) . ' (' . $sourceAfterMatchedCount . ' unfiltered)', + '[Scanned files] Before: ' . count($before->getFiles()) . ' (' . $before->getOriginalAmount() . ' unfiltered), After: ' . count($after->getFiles()) . ' (' . $after->getOriginalAmount() . ' unfiltered)', 'Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB' ), true diff --git a/src/PHPSemVerCheckerGit/ProcessedFileList.php b/src/PHPSemVerCheckerGit/ProcessedFileList.php new file mode 100644 index 0000000..98ed105 --- /dev/null +++ b/src/PHPSemVerCheckerGit/ProcessedFileList.php @@ -0,0 +1,59 @@ +originalAmount = $originalAmount; + $this->files = $files; + $this->scanner = $scanner; + } + + /** + * @return Scanner + */ + public function getScanner() + { + return $this->scanner; + } + + /** + * @return int + */ + public function getOriginalAmount() + { + return $this->originalAmount; + } + + /** + * @return string[] + */ + public function getFiles() + { + return $this->files; + } + +} \ No newline at end of file diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php index 4f229dd..bc209b3 100644 --- a/src/PHPSemVerCheckerGit/SourceFileProcessor.php +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -22,6 +22,10 @@ class SourceFileProcessor * @var Finder */ private $finder; + /** + * @var SourceFilter + */ + private $filter; /** * @var string */ @@ -45,41 +49,33 @@ public function __construct(SourceFilter $filter, Repository $repository, Output $this->repository = $repository; $this->output = $output; $this->finder = $finder; + $this->filter = $filter; $this->directory = $directory; - $this->addModifiedFiles($modifiedFiles); - } - - /** - * @param string[] $modified - */ - private function addModifiedFiles(array $modified) { - foreach($modified as $file) { + foreach($modifiedFiles as $file) { if(substr($file, -4) === '.php') { $this->modifiedFiles[] = $file; } } } - /** - * @param Scanner $scanner * @param string $commitIdentifier * @param $include * @param $exclude - * @return array + * @return ProcessedFileList */ public function processFileList( - Scanner &$scanner, $commitIdentifier, $include, $exclude ) { + $scanner = new Scanner(); $this->repository->checkout($commitIdentifier . ' --'); $source = $this->finder->findFromString($this->directory, $include, $exclude); $count = count($source); $source = $this->filter->filter($source, $this->modifiedFiles); $this->scanFileList($scanner, $source); - return array($count, $source); + return new ProcessedFileList($count, $source, $scanner); } /** From 494ef034783fb38a64cbf4750fa1c06342a0601b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:47:03 +0100 Subject: [PATCH 05/16] adding missing use statements --- src/PHPSemVerCheckerGit/SourceFileProcessor.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php index bc209b3..ed784fe 100644 --- a/src/PHPSemVerCheckerGit/SourceFileProcessor.php +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -7,6 +7,8 @@ use PHPSemVerChecker\Scanner\Scanner; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Helper\ProgressBar; +use PHPSemVerCheckerGit\Filter\SourceFilter; +use Gitter\Repository; class SourceFileProcessor { From 88d5295e342b159afe1ab7931c72c0403ac5cb4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:48:39 +0100 Subject: [PATCH 06/16] adding missing use statement --- src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 7c2bc59..25a941a 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -17,6 +17,7 @@ use vierbergenlars\SemVer\expression as SemanticExpression; use vierbergenlars\SemVer\SemVerException as SemanticVersionException; use vierbergenlars\SemVer\version as SemanticVersion; +use PHPSemVerChecker\Report\Report; class SuggestCommand extends BaseCommand { From 7e5eaeb2d6952a29974a108275647bde7f7008e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:49:50 +0100 Subject: [PATCH 07/16] adding missing use statement --- src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 25a941a..a2f389d 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -18,6 +18,7 @@ use vierbergenlars\SemVer\SemVerException as SemanticVersionException; use vierbergenlars\SemVer\version as SemanticVersion; use PHPSemVerChecker\Report\Report; +use vierbergenlars\SemVer\version; class SuggestCommand extends BaseCommand { From de62b4868bdf03d43bf5f47220e3be7b15e20804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:53:08 +0100 Subject: [PATCH 08/16] using use statement --- .../Console/Command/SuggestCommand.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index a2f389d..47ffa1d 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -18,7 +18,6 @@ use vierbergenlars\SemVer\SemVerException as SemanticVersionException; use vierbergenlars\SemVer\version as SemanticVersion; use PHPSemVerChecker\Report\Report; -use vierbergenlars\SemVer\version; class SuggestCommand extends BaseCommand { @@ -53,7 +52,7 @@ private function getRepository($directory) /** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output - * @return void + * @return int */ protected function execute(InputInterface $input, OutputInterface $output) { @@ -68,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if ($tag === null) { $output->writeln('No tags to suggest against'); - return; + return 1; } $output->writeln('Testing ' . $against . ' against tag: ' . $tag . ''); @@ -133,15 +132,15 @@ protected function execute(InputInterface $input, OutputInterface $output) ), true ); + return 0; } /** * @param Report $report - * @param version $tag + * @param SemanticVersion $tag * @return SemanticVersion - * @throws \vierbergenlars\SemVer\LogicException */ - private function getNextTag(Report $report, version $tag) + private function getNextTag(Report $report, SemanticVersion $tag) { $newTag = new SemanticVersion($tag); $suggestedLevel = $report->getSuggestedLevel(); From 0e425a037ce55ba66b1dad9d0db187eff1851696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Tue, 20 Mar 2018 23:56:26 +0100 Subject: [PATCH 09/16] using exit code of run properly --- bin/php-semver-checker-git | 3 +-- src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/bin/php-semver-checker-git b/bin/php-semver-checker-git index 353a978..04307c4 100755 --- a/bin/php-semver-checker-git +++ b/bin/php-semver-checker-git @@ -8,8 +8,7 @@ foreach (array( if (file_exists($path)) { require($path); $app = new PHPSemVerCheckerGit\Console\Application(); - $app->run(new PHPSemVerChecker\Console\InspectableArgvInput()); - exit(0); + die($app->run(new PHPSemVerChecker\Console\InspectableArgvInput())); } } diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 47ffa1d..6f495b0 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -55,7 +55,7 @@ private function getRepository($directory) * @return int */ protected function execute(InputInterface $input, OutputInterface $output) - { + { $startTime = microtime(true); $targetDirectory = getcwd(); From c565d4e1f5029567b88b250588ce591b5d9079bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Wed, 21 Mar 2018 00:39:03 +0100 Subject: [PATCH 10/16] adding some simple tests version incrementing --- composer.json | 5 +- composer.lock | 191 ++++---------------- test/Console/Command/SuggestCommandTest.php | 67 +++++++ 3 files changed, 108 insertions(+), 155 deletions(-) create mode 100644 test/Console/Command/SuggestCommandTest.php diff --git a/composer.json b/composer.json index b1c417f..bf41b45 100644 --- a/composer.json +++ b/composer.json @@ -35,8 +35,7 @@ "vierbergenlars/php-semver": "^3.0" }, "require-dev": { - "mockery/mockery": "^1.0", - "phpunit/phpunit": "^4.0|^5.0" + "phpunit/phpunit": "^4.8.36|^5.7.27" }, "bin": [ "bin/php-semver-checker-git" @@ -48,7 +47,7 @@ }, "autoload-dev": { "psr-4": { - "PHPSemVerCheckerGit\\Test\\": "tests/PHPSemVerCheckerGit" + "PHPSemVerCheckerGit\\Test\\": "test" } }, "config": { diff --git a/composer.lock b/composer.lock index d7246b5..1cbf926 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "fd8881f82ae2817293af2d6e07233276", + "content-hash": "d890a9287ae2a1670bb5a86ead2b1050", "packages": [ { "name": "hassankhan/config", @@ -113,20 +113,20 @@ "source": "https://github.com/tomzx/gitter/tree/php-semver-checker", "issues": "https://github.com/tomzx/gitter/issues" }, - "time": "2015-06-28T00:49:30+00:00" + "time": "2015-06-28 00:49:30" }, { "name": "nikic/php-parser", - "version": "v3.1.4", + "version": "v3.1.5", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078" + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/e57b3a09784f846411aa7ed664eedb73e3399078", - "reference": "e57b3a09784f846411aa7ed664eedb73e3399078", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", + "reference": "bb87e28e7d7b8d9a7fda231d37457c9210faf6ce", "shasum": "" }, "require": { @@ -164,7 +164,7 @@ "parser", "php" ], - "time": "2018-01-25T21:31:33+00:00" + "time": "2018-02-28T20:30:58+00:00" }, { "name": "psr/log", @@ -215,16 +215,16 @@ }, { "name": "symfony/console", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "26b6f419edda16c19775211987651cb27baea7f1" + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/26b6f419edda16c19775211987651cb27baea7f1", - "reference": "26b6f419edda16c19775211987651cb27baea7f1", + "url": "https://api.github.com/repos/symfony/console/zipball/067339e9b8ec30d5f19f5950208893ff026b94f7", + "reference": "067339e9b8ec30d5f19f5950208893ff026b94f7", "shasum": "" }, "require": { @@ -280,20 +280,20 @@ ], "description": "Symfony Console Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-26T15:46:28+00:00" }, { "name": "symfony/debug", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937" + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/53f6af2805daf52a43b393b93d2f24925d35c937", - "reference": "53f6af2805daf52a43b393b93d2f24925d35c937", + "url": "https://api.github.com/repos/symfony/debug/zipball/9b1071f86e79e1999b3d3675d2e0e7684268b9bc", + "reference": "9b1071f86e79e1999b3d3675d2e0e7684268b9bc", "shasum": "" }, "require": { @@ -336,7 +336,7 @@ ], "description": "Symfony Debug Component", "homepage": "https://symfony.com", - "time": "2018-01-18T22:16:57+00:00" + "time": "2018-02-28T21:49:22+00:00" }, { "name": "symfony/polyfill-mbstring", @@ -399,16 +399,16 @@ }, { "name": "symfony/process", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d" + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/09a5172057be8fc677840e591b17f385e58c7c0d", - "reference": "09a5172057be8fc677840e591b17f385e58c7c0d", + "url": "https://api.github.com/repos/symfony/process/zipball/cc4aea21f619116aaf1c58016a944e4821c8e8af", + "reference": "cc4aea21f619116aaf1c58016a944e4821c8e8af", "shasum": "" }, "require": { @@ -444,20 +444,20 @@ ], "description": "Symfony Process Component", "homepage": "https://symfony.com", - "time": "2018-01-29T09:03:43+00:00" + "time": "2018-02-12T17:55:00+00:00" }, { "name": "symfony/yaml", - "version": "v3.4.4", + "version": "v3.4.6", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe" + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/eab73b6c21d27ae4cd037c417618dfd4befb0bfe", - "reference": "eab73b6c21d27ae4cd037c417618dfd4befb0bfe", + "url": "https://api.github.com/repos/symfony/yaml/zipball/6af42631dcf89e9c616242c900d6c52bd53bd1bb", + "reference": "6af42631dcf89e9c616242c900d6c52bd53bd1bb", "shasum": "" }, "require": { @@ -502,7 +502,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2018-01-21T19:05:02+00:00" + "time": "2018-02-16T09:50:28+00:00" }, { "name": "tomzx/finder", @@ -555,16 +555,16 @@ }, { "name": "tomzx/php-semver-checker", - "version": "v0.12.0", + "version": "v0.12.1", "source": { "type": "git", "url": "https://github.com/tomzx/php-semver-checker.git", - "reference": "9930230655d48c5e21afe3c7c2396115a49ae5ae" + "reference": "9e86860dfdea8ef4a69c6834665521d2ae7899e8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tomzx/php-semver-checker/zipball/9930230655d48c5e21afe3c7c2396115a49ae5ae", - "reference": "9930230655d48c5e21afe3c7c2396115a49ae5ae", + "url": "https://api.github.com/repos/tomzx/php-semver-checker/zipball/9e86860dfdea8ef4a69c6834665521d2ae7899e8", + "reference": "9e86860dfdea8ef4a69c6834665521d2ae7899e8", "shasum": "" }, "require": { @@ -585,7 +585,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "0.12-dev" + "dev-master": "0.13-dev" } }, "autoload": { @@ -611,7 +611,7 @@ "semantic versioning", "semver" ], - "time": "2018-02-08T21:36:08+00:00" + "time": "2018-02-08T22:27:57+00:00" }, { "name": "vierbergenlars/php-semver", @@ -721,119 +721,6 @@ ], "time": "2015-06-14T21:17:01+00:00" }, - { - "name": "hamcrest/hamcrest-php", - "version": "v2.0.0", - "source": { - "type": "git", - "url": "https://github.com/hamcrest/hamcrest-php.git", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/hamcrest/hamcrest-php/zipball/776503d3a8e85d4f9a1148614f95b7a608b046ad", - "reference": "776503d3a8e85d4f9a1148614f95b7a608b046ad", - "shasum": "" - }, - "require": { - "php": "^5.3|^7.0" - }, - "replace": { - "cordoval/hamcrest-php": "*", - "davedevelopment/hamcrest-php": "*", - "kodova/hamcrest-php": "*" - }, - "require-dev": { - "phpunit/php-file-iterator": "1.3.3", - "phpunit/phpunit": "~4.0", - "satooshi/php-coveralls": "^1.0" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0-dev" - } - }, - "autoload": { - "classmap": [ - "hamcrest" - ] - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD" - ], - "description": "This is the PHP port of Hamcrest Matchers", - "keywords": [ - "test" - ], - "time": "2016-01-20T08:20:44+00:00" - }, - { - "name": "mockery/mockery", - "version": "1.0", - "source": { - "type": "git", - "url": "https://github.com/mockery/mockery.git", - "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/1bac8c362b12f522fdd1f1fa3556284c91affa38", - "reference": "1bac8c362b12f522fdd1f1fa3556284c91affa38", - "shasum": "" - }, - "require": { - "hamcrest/hamcrest-php": "~2.0", - "lib-pcre": ">=7.0", - "php": ">=5.6.0" - }, - "require-dev": { - "phpunit/phpunit": "~5.7|~6.1" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "autoload": { - "psr-0": { - "Mockery": "library/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "BSD-3-Clause" - ], - "authors": [ - { - "name": "Pádraic Brady", - "email": "padraic.brady@gmail.com", - "homepage": "http://blog.astrumfutura.com" - }, - { - "name": "Dave Marshall", - "email": "dave.marshall@atstsolutions.co.uk", - "homepage": "http://davedevelopment.co.uk" - } - ], - "description": "Mockery is a simple yet flexible PHP mock object framework for use in unit testing with PHPUnit, PHPSpec or any other testing framework. Its core goal is to offer a test double framework with a succinct API capable of clearly defining all possible object operations and interactions using a human readable Domain Specific Language (DSL). Designed as a drop in alternative to PHPUnit's phpunit-mock-objects library, Mockery is easy to integrate with PHPUnit and can operate alongside phpunit-mock-objects without the World ending.", - "homepage": "http://github.com/mockery/mockery", - "keywords": [ - "BDD", - "TDD", - "library", - "mock", - "mock objects", - "mockery", - "stub", - "test", - "test double", - "testing" - ], - "time": "2017-10-06T16:20:43+00:00" - }, { "name": "myclabs/deep-copy", "version": "1.7.0", @@ -1027,16 +914,16 @@ }, { "name": "phpspec/prophecy", - "version": "1.7.3", + "version": "1.7.5", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf" + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", - "reference": "e4ed002c67da8eceb0eb8ddb8b3847bb53c5c2bf", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/dfd6be44111a7c41c2e884a336cc4f461b3b2401", + "reference": "dfd6be44111a7c41c2e884a336cc4f461b3b2401", "shasum": "" }, "require": { @@ -1048,7 +935,7 @@ }, "require-dev": { "phpspec/phpspec": "^2.5|^3.2", - "phpunit/phpunit": "^4.8.35 || ^5.7" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.5" }, "type": "library", "extra": { @@ -1086,7 +973,7 @@ "spy", "stub" ], - "time": "2017-11-24T13:59:53+00:00" + "time": "2018-02-19T10:16:54+00:00" }, { "name": "phpunit/php-code-coverage", diff --git a/test/Console/Command/SuggestCommandTest.php b/test/Console/Command/SuggestCommandTest.php new file mode 100644 index 0000000..994fd74 --- /dev/null +++ b/test/Console/Command/SuggestCommandTest.php @@ -0,0 +1,67 @@ +getMockedVersion(0,1,0), '0.1.0'), + array(Level::PATCH, $this->getMockedVersion(0,1,0), '0.1.1'), + array(Level::MINOR, $this->getMockedVersion(0,1,0), '0.2.0'), + array(Level::MAJOR, $this->getMockedVersion(0,1,0), '0.2.0'), + //v1.0.0 + array(Level::NONE, $this->getMockedVersion(1,0,0), '1.0.0'), + array(Level::PATCH, $this->getMockedVersion(1,0,0), '1.0.1'), + array(Level::MINOR, $this->getMockedVersion(1,0,0), '1.1.0'), + array(Level::MAJOR, $this->getMockedVersion(1,0,0), '2.0.0'), + //v2.3.4 + array(Level::NONE, $this->getMockedVersion(2,3,4), '2.3.4'), + array(Level::PATCH, $this->getMockedVersion(2,3,4), '2.3.5'), + array(Level::MINOR, $this->getMockedVersion(2,3,4), '2.4.0'), + array(Level::MAJOR, $this->getMockedVersion(2,3,4), '3.0.0'), + ); + } + + /** + * @param $level + * @param $version + * @param $expected + * @throws \ReflectionException + * @test + * @dataProvider provideGetNextTag + */ + public function testGetNextTag($level, version $version, $expected) { + $report = $this->getMockBuilder('PHPSemVerChecker\Report\Report')->disableOriginalConstructor()->getMock(); + $report->expects($this->once())->method('getSuggestedLevel')->willReturn($level); + $instance = new SuggestCommand(); + $rc = new \ReflectionClass('PHPSemVerCheckerGit\Console\Command\SuggestCommand'); + $method = $rc->getMethod('getNextTag'); + $method->setAccessible(true); + $result = $method->invoke($instance, $report, $version); + $this->assertInstanceOf('vierbergenlars\SemVer\version', $result); + $this->assertEquals($expected, $result->getVersion()); + } +} \ No newline at end of file From 61743aa62f7348fc0c3e5b4752835ba134ecbff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Wed, 21 Mar 2018 00:41:57 +0100 Subject: [PATCH 11/16] adjusting unit test folder in config --- phpunit.xml.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index c4c78cc..4a5a39b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,6 +1,6 @@ - ./tests + ./test From 8d873fd5f457c75fd4ac418a0f37f0eb95e34377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Wed, 21 Mar 2018 00:49:32 +0100 Subject: [PATCH 12/16] adding pre-release testcases --- test/Console/Command/SuggestCommandTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/Console/Command/SuggestCommandTest.php b/test/Console/Command/SuggestCommandTest.php index 994fd74..057fb47 100644 --- a/test/Console/Command/SuggestCommandTest.php +++ b/test/Console/Command/SuggestCommandTest.php @@ -32,6 +32,11 @@ public function provideGetNextTag() { array(Level::PATCH, $this->getMockedVersion(0,1,0), '0.1.1'), array(Level::MINOR, $this->getMockedVersion(0,1,0), '0.2.0'), array(Level::MAJOR, $this->getMockedVersion(0,1,0), '0.2.0'), + //v1.0.0RC1 + array(Level::NONE, $this->getMockedVersion(1,0,'0-1'), '1.0.0-1'), + array(Level::PATCH, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), + array(Level::MINOR, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), + array(Level::MAJOR, $this->getMockedVersion(1,0,'0-1'), '1.0.0-2'), //v1.0.0 array(Level::NONE, $this->getMockedVersion(1,0,0), '1.0.0'), array(Level::PATCH, $this->getMockedVersion(1,0,0), '1.0.1'), From 49cf635ea9adbd985fab369567622fb9c6df86b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Sat, 14 Apr 2018 13:36:40 +0200 Subject: [PATCH 13/16] removing useless references adjusting ordering of use statements in SuggestCommand adjusting ProcessedFileList to hold the actual file lists removing useless linebreaks from method definition extracting reflecting in test for easier readability --- .../Console/Command/SuggestCommand.php | 15 +++--- src/PHPSemVerCheckerGit/ProcessedFileList.php | 53 ++++++++++++++----- .../SourceFileProcessor.php | 15 ++---- test/Console/Command/SuggestCommandTest.php | 29 +++++++--- 4 files changed, 75 insertions(+), 37 deletions(-) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 6f495b0..b3e502f 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -5,7 +5,9 @@ use Gitter\Client; use Gitter\Repository; use PHPSemVerChecker\Analyzer\Analyzer; +use PHPSemVerChecker\Console\Command\BaseCommand; use PHPSemVerChecker\Finder\Finder; +use PHPSemVerChecker\Report\Report; use PHPSemVerChecker\Reporter\Reporter; use PHPSemVerChecker\SemanticVersioning\Level; use PHPSemVerCheckerGit\Filter\SourceFilter; @@ -17,7 +19,6 @@ use vierbergenlars\SemVer\expression as SemanticExpression; use vierbergenlars\SemVer\SemVerException as SemanticVersionException; use vierbergenlars\SemVer\version as SemanticVersion; -use PHPSemVerChecker\Report\Report; class SuggestCommand extends BaseCommand { @@ -50,8 +51,8 @@ private function getRepository($directory) } /** - * @param \Symfony\Component\Console\Input\InputInterface $input - * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param InputInterface $input + * @param OutputInterface $output * @return int */ protected function execute(InputInterface $input, OutputInterface $output) @@ -127,7 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->write( array( '', - '[Scanned files] Before: ' . count($before->getFiles()) . ' (' . $before->getOriginalAmount() . ' unfiltered), After: ' . count($after->getFiles()) . ' (' . $after->getOriginalAmount() . ' unfiltered)', + '[Scanned files] Before: ' . $before->getFilteredAmount() . ' (' . $before->getUnfilteredAmount() . ' unfiltered), After: ' . $after->getFilteredAmount() . ' (' . $after->getUnfilteredAmount() . ' unfiltered)', 'Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB' ), true @@ -173,7 +174,7 @@ private function getInitialTag(Repository $repository) } /** - * @param \Gitter\Repository $repository + * @param Repository $repository * @return string|null */ protected function findLatestTag(Repository $repository) @@ -182,7 +183,7 @@ protected function findLatestTag(Repository $repository) } /** - * @param \Gitter\Repository $repository + * @param Repository $repository * @param string $tag * @return string|null */ @@ -219,7 +220,7 @@ private function filterTags(array $tags) /** * @param string[] $tags - * @param \vierbergenlars\SemVer\version|string|null $versionTag + * @param SemanticVersion|string|null $versionTag * @return string|null */ private function getMappedVersionTag(array $tags, $versionTag) diff --git a/src/PHPSemVerCheckerGit/ProcessedFileList.php b/src/PHPSemVerCheckerGit/ProcessedFileList.php index 98ed105..e555d68 100644 --- a/src/PHPSemVerCheckerGit/ProcessedFileList.php +++ b/src/PHPSemVerCheckerGit/ProcessedFileList.php @@ -9,11 +9,23 @@ class ProcessedFileList /** * @var int */ - private $originalAmount; + private $unfilteredAmount; + + /** + * @var int + */ + private $filteredAmount; + + /** + * @var string[] + */ + private $filtered; + /** * @var string[] */ - private $files; + private $unfiltered; + /** * @var Scanner */ @@ -21,14 +33,16 @@ class ProcessedFileList /** * ProcessedFileList constructor. - * @param int $originalAmount - * @param string[] $files + * @param string[] $unfiltered + * @param string[] $filtered * @param Scanner $scanner */ - public function __construct($originalAmount, array &$files, Scanner &$scanner) + public function __construct(array $unfiltered, array $filtered, Scanner &$scanner) { - $this->originalAmount = $originalAmount; - $this->files = $files; + $this->unfilteredAmount = count($unfiltered); + $this->filteredAmount = count($filtered); + $this->filtered = $filtered; + $this->unfiltered = $unfiltered; $this->scanner = $scanner; } @@ -40,20 +54,35 @@ public function getScanner() return $this->scanner; } + /** + * @return string[] + */ + public function getFiltered() + { + return $this->filtered; + } + /** * @return int */ - public function getOriginalAmount() + public function getFilteredAmount() { - return $this->originalAmount; + return $this->filteredAmount; } /** - * @return string[] + * @return int */ - public function getFiles() + public function getUnfilteredAmount() { - return $this->files; + return $this->unfilteredAmount; } + /** + * @return string[] + */ + public function getUnfiltered() + { + return $this->unfiltered; + } } \ No newline at end of file diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php index ed784fe..6762804 100644 --- a/src/PHPSemVerCheckerGit/SourceFileProcessor.php +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -66,25 +66,21 @@ public function __construct(SourceFilter $filter, Repository $repository, Output * @param $exclude * @return ProcessedFileList */ - public function processFileList( - $commitIdentifier, - $include, - $exclude - ) { + public function processFileList($commitIdentifier, $include, $exclude) + { $scanner = new Scanner(); $this->repository->checkout($commitIdentifier . ' --'); - $source = $this->finder->findFromString($this->directory, $include, $exclude); - $count = count($source); + $unfiltered = $this->finder->findFromString($this->directory, $include, $exclude); $source = $this->filter->filter($source, $this->modifiedFiles); $this->scanFileList($scanner, $source); - return new ProcessedFileList($count, $source, $scanner); + return new ProcessedFileList($unfiltered, $source, $scanner); } /** * @param Scanner $scanner * @param array $files */ - private function scanFileList(Scanner &$scanner, array &$files) + private function scanFileList(Scanner $scanner, array $files) { $progress = new ProgressBar($this->output, count($files)); foreach ($files as $file) { @@ -93,5 +89,4 @@ private function scanFileList(Scanner &$scanner, array &$files) } $progress->clear(); } - } \ No newline at end of file diff --git a/test/Console/Command/SuggestCommandTest.php b/test/Console/Command/SuggestCommandTest.php index 057fb47..26cac67 100644 --- a/test/Console/Command/SuggestCommandTest.php +++ b/test/Console/Command/SuggestCommandTest.php @@ -2,9 +2,12 @@ namespace PHPSemVerCheckerGit\Test; +use PHPSemVerChecker\SemanticVersioning\Level; use PHPSemVerCheckerGit\Console\Command\SuggestCommand; use PHPUnit\Framework\TestCase; -use PHPSemVerChecker\SemanticVersioning\Level; +use ReflectionClass; +use ReflectionException; +use ReflectionMethod; use vierbergenlars\SemVer\version; class SuggestCommandTest extends TestCase @@ -21,6 +24,18 @@ private function getMockedVersion($major, $minor, $patch) return new version("$major.$minor.$patch", true); } + /** + * @return ReflectionMethod + * @throws ReflectionException + */ + private function getNextTagMethod() + { + $class = new ReflectionClass('PHPSemVerCheckerGit\Console\Command\SuggestCommand'); + $method = $class->getMethod('getNextTag'); + $method->setAccessible(true); + return $method; + } + /** * Provides a few test cases * @return array @@ -54,18 +69,16 @@ public function provideGetNextTag() { * @param $level * @param $version * @param $expected - * @throws \ReflectionException + * @throws ReflectionException * @test * @dataProvider provideGetNextTag */ - public function testGetNextTag($level, version $version, $expected) { + public function testGetNextTag($level, version $version, $expected) + { $report = $this->getMockBuilder('PHPSemVerChecker\Report\Report')->disableOriginalConstructor()->getMock(); $report->expects($this->once())->method('getSuggestedLevel')->willReturn($level); - $instance = new SuggestCommand(); - $rc = new \ReflectionClass('PHPSemVerCheckerGit\Console\Command\SuggestCommand'); - $method = $rc->getMethod('getNextTag'); - $method->setAccessible(true); - $result = $method->invoke($instance, $report, $version); + + $result = $this->getNextTagMethod()->invoke(new SuggestCommand(), $report, $version); $this->assertInstanceOf('vierbergenlars\SemVer\version', $result); $this->assertEquals($expected, $result->getVersion()); } From 0899176f084ca5ddef535f33207c0f1268961c63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Sat, 14 Apr 2018 13:44:22 +0200 Subject: [PATCH 14/16] fixing issues found by scrutinizer --- src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php | 1 - src/PHPSemVerCheckerGit/SourceFileProcessor.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index b3e502f..010923c 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -5,7 +5,6 @@ use Gitter\Client; use Gitter\Repository; use PHPSemVerChecker\Analyzer\Analyzer; -use PHPSemVerChecker\Console\Command\BaseCommand; use PHPSemVerChecker\Finder\Finder; use PHPSemVerChecker\Report\Report; use PHPSemVerChecker\Reporter\Reporter; diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php index 6762804..97114e6 100644 --- a/src/PHPSemVerCheckerGit/SourceFileProcessor.php +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -71,7 +71,7 @@ public function processFileList($commitIdentifier, $include, $exclude) $scanner = new Scanner(); $this->repository->checkout($commitIdentifier . ' --'); $unfiltered = $this->finder->findFromString($this->directory, $include, $exclude); - $source = $this->filter->filter($source, $this->modifiedFiles); + $source = $this->filter->filter($unfiltered, $this->modifiedFiles); $this->scanFileList($scanner, $source); return new ProcessedFileList($unfiltered, $source, $scanner); } From 1645081d8a3ff98c1cddc08a84acf16ea63b027f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Sat, 14 Apr 2018 18:46:26 +0200 Subject: [PATCH 15/16] reverting file to f0abc36 --- bin/php-semver-checker-git | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/bin/php-semver-checker-git b/bin/php-semver-checker-git index 04307c4..a91d1b5 100755 --- a/bin/php-semver-checker-git +++ b/bin/php-semver-checker-git @@ -1,18 +1,28 @@ #!/usr/bin/env php run(new PHPSemVerChecker\Console\InspectableArgvInput())); + require $path; + $found = true; + break; } } -die( - 'php-semver-checker-git requires to be installed through composer.'.PHP_EOL. - 'See http://getcomposer.org/download/'.PHP_EOL -); \ No newline at end of file +if (!$found) { + die( + 'php-semver-checker-git requires to be installed through composer.'.PHP_EOL. + 'See http://getcomposer.org/download/'.PHP_EOL + ); +} + +ini_set('xdebug.max_nesting_level', 5000); + +$app = new PHPSemVerCheckerGit\Console\Application(); +$app->run(new PHPSemVerChecker\Console\InspectableArgvInput()); From 54c53241e45a46d9876c82401f7b3829f6ad19a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20B=C3=BCttner?= Date: Sat, 14 Apr 2018 19:38:04 +0200 Subject: [PATCH 16/16] restoring FQN for phpdoc changing Amount to Count for list size --- .../Console/Command/SuggestCommand.php | 26 ++++++++------- src/PHPSemVerCheckerGit/ProcessedFileList.php | 22 ++++++------- .../SourceFileProcessor.php | 32 +++++++++++-------- test/Console/Command/SuggestCommandTest.php | 12 +++---- 4 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php index 010923c..32bb6e3 100644 --- a/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php +++ b/src/PHPSemVerCheckerGit/Console/Command/SuggestCommand.php @@ -41,7 +41,7 @@ protected function configure() /** * @param string $directory - * @return Repository + * @return \Gitter\Repository */ private function getRepository($directory) { @@ -49,11 +49,11 @@ private function getRepository($directory) return $client->getRepository($directory); } - /** - * @param InputInterface $input - * @param OutputInterface $output + /** + * @param \Symfony\Component\Console\Input\InputInterface $input + * @param \Symfony\Component\Console\Output\OutputInterface $output * @return int - */ + */ protected function execute(InputInterface $input, OutputInterface $output) { $startTime = microtime(true); @@ -127,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->write( array( '', - '[Scanned files] Before: ' . $before->getFilteredAmount() . ' (' . $before->getUnfilteredAmount() . ' unfiltered), After: ' . $after->getFilteredAmount() . ' (' . $after->getUnfilteredAmount() . ' unfiltered)', + '[Scanned files] Before: ' . $before->getFilteredCount() . ' (' . $before->getUnfilteredCount() . ' unfiltered), After: ' . $after->getFilteredCount() . ' (' . $after->getUnfilteredCount() . ' unfiltered)', 'Time: ' . round($duration, 3) . ' seconds, Memory: ' . round(memory_get_peak_usage() / 1024 / 1024, 3) . ' MB' ), true @@ -136,7 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output) } /** - * @param Report $report + * @param \PHPSemVerChecker\Report\Report $report * @param SemanticVersion $tag * @return SemanticVersion */ @@ -160,7 +160,7 @@ private function getNextTag(Report $report, SemanticVersion $tag) } /** - * @param Repository $repository + * @param \Gitter\Repository $repository * @return null|string */ private function getInitialTag(Repository $repository) @@ -173,7 +173,7 @@ private function getInitialTag(Repository $repository) } /** - * @param Repository $repository + * @param \Gitter\Repository $repository * @return string|null */ protected function findLatestTag(Repository $repository) @@ -182,7 +182,7 @@ protected function findLatestTag(Repository $repository) } /** - * @param Repository $repository + * @param \Gitter\Repository $repository * @param string $tag * @return string|null */ @@ -203,6 +203,10 @@ protected function findTag(Repository $repository, $tag) return $this->getMappedVersionTag($tags, $satisfyingTag); } + /** + * @param array $tags + * @return array + */ private function filterTags(array $tags) { $filteredTags = []; @@ -218,7 +222,7 @@ private function filterTags(array $tags) } /** - * @param string[] $tags + * @param string[] $tags * @param SemanticVersion|string|null $versionTag * @return string|null */ diff --git a/src/PHPSemVerCheckerGit/ProcessedFileList.php b/src/PHPSemVerCheckerGit/ProcessedFileList.php index e555d68..48a8172 100644 --- a/src/PHPSemVerCheckerGit/ProcessedFileList.php +++ b/src/PHPSemVerCheckerGit/ProcessedFileList.php @@ -9,12 +9,12 @@ class ProcessedFileList /** * @var int */ - private $unfilteredAmount; + private $unfilteredCount; /** * @var int */ - private $filteredAmount; + private $filteredCount; /** * @var string[] @@ -27,7 +27,7 @@ class ProcessedFileList private $unfiltered; /** - * @var Scanner + * @var \PHPSemVerChecker\Scanner\Scanner */ private $scanner; @@ -35,19 +35,19 @@ class ProcessedFileList * ProcessedFileList constructor. * @param string[] $unfiltered * @param string[] $filtered - * @param Scanner $scanner + * @param \PHPSemVerChecker\Scanner\Scanner $scanner */ public function __construct(array $unfiltered, array $filtered, Scanner &$scanner) { - $this->unfilteredAmount = count($unfiltered); - $this->filteredAmount = count($filtered); + $this->unfilteredCount = count($unfiltered); + $this->filteredCount = count($filtered); $this->filtered = $filtered; $this->unfiltered = $unfiltered; $this->scanner = $scanner; } /** - * @return Scanner + * @return \PHPSemVerChecker\Scanner\Scanner */ public function getScanner() { @@ -65,17 +65,17 @@ public function getFiltered() /** * @return int */ - public function getFilteredAmount() + public function getFilteredCount() { - return $this->filteredAmount; + return $this->filteredCount; } /** * @return int */ - public function getUnfilteredAmount() + public function getUnfilteredCount() { - return $this->unfilteredAmount; + return $this->unfilteredCount; } /** diff --git a/src/PHPSemVerCheckerGit/SourceFileProcessor.php b/src/PHPSemVerCheckerGit/SourceFileProcessor.php index 97114e6..eba3dc6 100644 --- a/src/PHPSemVerCheckerGit/SourceFileProcessor.php +++ b/src/PHPSemVerCheckerGit/SourceFileProcessor.php @@ -2,36 +2,40 @@ namespace PHPSemVerCheckerGit; - +use Gitter\Repository; use PHPSemVerChecker\Finder\Finder; use PHPSemVerChecker\Scanner\Scanner; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\ProgressBar; use PHPSemVerCheckerGit\Filter\SourceFilter; -use Gitter\Repository; +use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Output\OutputInterface; class SourceFileProcessor { /** - * @var Repository + * @var \Gitter\Repository */ private $repository; + /** - * @var OutputInterface + * @var \Symfony\Component\Console\Output\OutputInterface */ private $output; + /** - * @var Finder + * @var \PHPSemVerChecker\Finder\Finder */ private $finder; + /** - * @var SourceFilter + * @var \PHPSemVerCheckerGit\Filter\SourceFilter */ private $filter; + /** * @var string */ private $directory; + /** * @var string[] */ @@ -39,10 +43,10 @@ class SourceFileProcessor /** * SourceFileProcessor constructor. - * @param SourceFilter &$filter - * @param Repository $repository - * @param OutputInterface $output - * @param Finder $finder + * @param PHPSemVerCheckerGit\Filter\SourceFilter $filter + * @param \Gitter\Repository $repository + * @param \Symfony\Component\Console\Output\OutputInterface $output + * @param \PHPSemVerChecker\Finder\Finder $finder * @param string $directory * @param string[] $modifiedFiles */ @@ -64,7 +68,7 @@ public function __construct(SourceFilter $filter, Repository $repository, Output * @param string $commitIdentifier * @param $include * @param $exclude - * @return ProcessedFileList + * @return \PHPSemVerCheckerGit\ProcessedFileList */ public function processFileList($commitIdentifier, $include, $exclude) { @@ -77,7 +81,7 @@ public function processFileList($commitIdentifier, $include, $exclude) } /** - * @param Scanner $scanner + * @param \PHPSemVerChecker\Scanner\Scanner $scanner * @param array $files */ private function scanFileList(Scanner $scanner, array $files) diff --git a/test/Console/Command/SuggestCommandTest.php b/test/Console/Command/SuggestCommandTest.php index 26cac67..327135b 100644 --- a/test/Console/Command/SuggestCommandTest.php +++ b/test/Console/Command/SuggestCommandTest.php @@ -6,8 +6,6 @@ use PHPSemVerCheckerGit\Console\Command\SuggestCommand; use PHPUnit\Framework\TestCase; use ReflectionClass; -use ReflectionException; -use ReflectionMethod; use vierbergenlars\SemVer\version; class SuggestCommandTest extends TestCase @@ -17,7 +15,7 @@ class SuggestCommandTest extends TestCase * @param int $major * @param int $minor * @param int $patch - * @return version + * @return \vierbergenlars\SemVer\version */ private function getMockedVersion($major, $minor, $patch) { @@ -25,8 +23,8 @@ private function getMockedVersion($major, $minor, $patch) } /** - * @return ReflectionMethod - * @throws ReflectionException + * @return \ReflectionMethod + * @throws \ReflectionException */ private function getNextTagMethod() { @@ -67,9 +65,9 @@ public function provideGetNextTag() { /** * @param $level - * @param $version + * @param \vierbergenlars\SemVer\version $version * @param $expected - * @throws ReflectionException + * @throws \ReflectionException * @test * @dataProvider provideGetNextTag */