Skip to content

Commit

Permalink
refactor the version alias in the migrations infos
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeSimonson committed Jan 11, 2016
1 parent fc24f14 commit e6e937f
Showing 1 changed file with 28 additions and 20 deletions.
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->getVersionAlias('prev'),
'Current Version' => $this->getVersionAlias('current'),
'Next Version' => $this->getVersionAlias('next'),
'Latest Version' => $this->getVersionAlias('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 getVersionAlias($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

0 comments on commit e6e937f

Please sign in to comment.