From b6bdf91aade2e80d2bf3b990cab9abea876db787 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draic=20Brady?= Date: Thu, 15 Jun 2017 22:03:23 +0100 Subject: [PATCH] Simplify command --- src/Console/Command/SelfUpdateCommand.php | 50 +++++------------------ src/Logger/UpdateConsoleLogger.php | 3 +- src/functions.php | 14 +++---- 3 files changed, 16 insertions(+), 51 deletions(-) diff --git a/src/Console/Command/SelfUpdateCommand.php b/src/Console/Command/SelfUpdateCommand.php index 0531e1f07..6d9d7309b 100644 --- a/src/Console/Command/SelfUpdateCommand.php +++ b/src/Console/Command/SelfUpdateCommand.php @@ -97,10 +97,8 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $io = new SymfonyStyle($input, $output); $this->logger = new UpdateConsoleLogger( - $this->getApplication(), - $io + new SymfonyStyle($input, $output) ); $this->output = $output; @@ -117,11 +115,6 @@ protected function execute(InputInterface $input, OutputInterface $output) return; } - $this->updateToStableBuild(); - } - - private function updateToStableBuild() - { $this->update($this->getStableUpdater()); } @@ -131,8 +124,11 @@ private function updateToStableBuild() private function getStableUpdater(): Updater { $this->updater->setStrategy(Updater::STRATEGY_GITHUB); + $this->updater->getStrategy()->setPackageName(self::PACKAGIST_PACKAGE_NAME); + $this->updater->getStrategy()->setPharName(self::REMOTE_FILENAME); + $this->updater->getStrategy()->setCurrentLocalVersion($this->version); - return $this->getGithubReleasesUpdater($updater); + return $this->updater; } private function update(Updater $updater) @@ -169,35 +165,23 @@ private function rollback() } private function printAvailableUpdates() - { - $this->printCurrentLocalVersion(); - $this->printCurrentStableVersion(); - } - - private function printCurrentLocalVersion() { $this->logger->printLocalVersion($this->version); + $this->printCurrentStableVersion(); } private function printCurrentStableVersion() { - $this->printVersion($this->getStableUpdater()); - } - - /** - * @param Updater $updater - */ - private function printVersion(Updater $updater) - { + $updater = $this->getStableUpdater(); $stability = self::STABILITY_STABLE; try { - if ($this->updater->hasUpdate()) { + if ($updater->hasUpdate()) { $this->logger->printRemoteVersion( $stability, - $this->updater->getNewVersion() + $updater->getNewVersion() ); - } elseif (false == $this->updater->getNewVersion()) { + } elseif (false == $updater->getNewVersion()) { $this->logger->noNewRemoteVersions($stability); } else { $this->logger->currentVersionInstalled($stability); @@ -207,20 +191,6 @@ private function printVersion(Updater $updater) } } - /** - * @param Updater $updater - * - * @return Updater - */ - private function getGithubReleasesUpdater(Updater $updater): Updater - { - $this->updater->getStrategy()->setPackageName(self::PACKAGIST_PACKAGE_NAME); - $this->updater->getStrategy()->setPharName(self::REMOTE_FILENAME); - $this->updater->getStrategy()->setCurrentLocalVersion($this->version); - - return $updater; - } - private function getLocalPharName(): string { return basename(\PHAR::running()); diff --git a/src/Logger/UpdateConsoleLogger.php b/src/Logger/UpdateConsoleLogger.php index 3ec2ee543..63eb07232 100644 --- a/src/Logger/UpdateConsoleLogger.php +++ b/src/Logger/UpdateConsoleLogger.php @@ -14,7 +14,6 @@ namespace Humbug\PhpScoper\Logger; -use Symfony\Component\Console\Application; use Symfony\Component\Console\Style\SymfonyStyle; /** @@ -33,7 +32,7 @@ class UpdateConsoleLogger */ private $io; - public function __construct(Application $application, SymfonyStyle $io) + public function __construct(SymfonyStyle $io) { $this->io = $io; $this->application = $application; diff --git a/src/functions.php b/src/functions.php index d01a6ee86..45d84ac21 100644 --- a/src/functions.php +++ b/src/functions.php @@ -46,7 +46,11 @@ function create_application(): SymfonyApplication ]); if ('phar:' === substr(__FILE__, 0, 5)) { - $app->add(new SelfUpdateCommand()); + $app->add( + new SelfUpdateCommand( + new Updater() + ) + ); } return $app; @@ -87,14 +91,6 @@ function create_parser(): Parser return (new ParserFactory())->create(ParserFactory::ONLY_PHP7); } -/** - * @private - */ -function create_updater(): Updater -{ - return new Updater(); -} - /** * @param string[] $paths Absolute paths *