Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the version alias in the migrations infos #418

Merged
merged 1 commit into from
Jan 13, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ public function __construct(Configuration $configuration)

public function getMigrationsInfos()
{
$formattedVersions = [];
foreach (['prev', 'current', 'next', 'latest'] as $alias) {
$version = $this->configuration->resolveVersionAlias($alias);
if ($version === null) {
if ($alias == 'next') {
$formattedVersions[$alias] = 'Already at latest version';
} elseif ($alias == 'prev') {
$formattedVersions[$alias] = 'Already at first version';
}
} elseif ($version === '0') {
$formattedVersions[$alias] = '<comment>0</comment>';
} else {
$formattedVersions[$alias] = $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';
}
}

$numExecutedUnavailableMigrations = count($this->executedUnavailableMigrations);
$numNewMigrations = count(array_diff($this->availableMigrations, $this->executedMigrations));

Expand All @@ -59,10 +43,10 @@ public function getMigrationsInfos()
'Version Column Name' => $this->configuration->getMigrationsColumnName(),
'Migrations Namespace' => $this->configuration->getMigrationsNamespace(),
'Migrations Directory' => $this->configuration->getMigrationsDirectory(),
'Previous Version' => $formattedVersions['prev'],
'Current Version' => $formattedVersions['current'],
'Next Version' => $formattedVersions['next'],
'Latest Version' => $formattedVersions['latest'],
'Previous Version' => $this->getFormattedVersionAlias('prev'),
'Current Version' => $this->getFormattedVersionAlias('current'),
'Next Version' => $this->getFormattedVersionAlias('next'),
'Latest Version' => $this->getFormattedVersionAlias('latest'),
'Executed Migrations' => count($this->executedMigrations),
'Executed Unavailable Migrations' => $numExecutedUnavailableMigrations,
'Available Migrations' => count($this->availableMigrations),
Expand All @@ -72,6 +56,30 @@ public function getMigrationsInfos()
return $infos;
}

private function getFormattedVersionAlias($alias)
{
$version = $this->configuration->resolveVersionAlias($alias);
//No version found
if ($version === null) {
if ($alias == 'next') {

return 'Already at latest version';
} elseif ($alias == 'prev') {

return 'Already at first version';
}
}
//Before first version "virtual" version number
if ($version === '0') {

return '<comment>0</comment>';
}

//Show normal version number
return $this->configuration->getDateTime($version) . ' (<comment>' . $version . '</comment>)';

}

/** @var Version[] */
public function getExecutedUnavailableMigrations()
{
Expand Down