Skip to content

Commit

Permalink
Simplify command
Browse files Browse the repository at this point in the history
  • Loading branch information
padraic committed Jun 19, 2017
1 parent 4bf01d7 commit b6bdf91
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 51 deletions.
50 changes: 10 additions & 40 deletions src/Console/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -117,11 +115,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
return;
}

$this->updateToStableBuild();
}

private function updateToStableBuild()
{
$this->update($this->getStableUpdater());
}

Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions src/Logger/UpdateConsoleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

namespace Humbug\PhpScoper\Logger;

use Symfony\Component\Console\Application;
use Symfony\Component\Console\Style\SymfonyStyle;

/**
Expand All @@ -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;
Expand Down
14 changes: 5 additions & 9 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*
Expand Down

0 comments on commit b6bdf91

Please sign in to comment.