Skip to content

Commit

Permalink
Merge pull request #428 from ReenExeContributor/clear-code
Browse files Browse the repository at this point in the history
after review
  • Loading branch information
mikeSimonson committed Feb 6, 2016
2 parents 360ad92 + fd3157c commit cdb33e4
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 43 deletions.
26 changes: 11 additions & 15 deletions lib/Doctrine/DBAL/Migrations/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,8 @@ public function getMigratedVersions()
$this->createMigrationTable();

$ret = $this->connection->fetchAll("SELECT " . $this->migrationsColumnName . " FROM " . $this->migrationsTableName);
$versions = [];
foreach ($ret as $version) {
$versions[] = current($version);
}

return $versions;
return array_map('current', $ret);
}

/**
Expand Down Expand Up @@ -708,22 +704,22 @@ public function createMigrationTable()
return false;
}

if (!$this->connection->getSchemaManager()->tablesExist([$this->migrationsTableName])) {
$columns = [
$this->migrationsColumnName => new Column($this->migrationsColumnName, Type::getType('string'), ['length' => 255]),
];
$table = new Table($this->migrationsTableName, $columns);
$table->setPrimaryKey([$this->migrationsColumnName]);
$this->connection->getSchemaManager()->createTable($table);

if ($this->connection->getSchemaManager()->tablesExist([$this->migrationsTableName])) {
$this->migrationTableCreated = true;

return true;
return false;
}

$columns = [
$this->migrationsColumnName => new Column($this->migrationsColumnName, Type::getType('string'), ['length' => 255]),
];
$table = new Table($this->migrationsTableName, $columns);
$table->setPrimaryKey([$this->migrationsColumnName]);
$this->connection->getSchemaManager()->createTable($table);

$this->migrationTableCreated = true;

return false;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,25 @@ private function getOutputWriter(OutputInterface $output)
*/
private function getConnection(InputInterface $input)
{
if (!$this->connection) {
$chainLoader = new ConnectionConfigurationChainLoader(
[
new ArrayConnectionConfigurationLoader($input->getOption('db-configuration')),
new ArrayConnectionConfigurationLoader('migrations-db.php'),
new ConnectionHelperLoader($this->getHelperSet(), 'connection'),
new ConnectionConfigurationLoader($this->configuration),
]
);
$connection = $chainLoader->chosen();

if ($connection) {
$this->connection = $connection;

return $this->connection;
}
if ($this->connection) {
return $this->connection;
}

throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.');
$chainLoader = new ConnectionConfigurationChainLoader(
[
new ArrayConnectionConfigurationLoader($input->getOption('db-configuration')),
new ArrayConnectionConfigurationLoader('migrations-db.php'),
new ConnectionHelperLoader($this->getHelperSet(), 'connection'),
new ConnectionConfigurationLoader($this->configuration),
]
);
$connection = $chainLoader->chosen();

if ($connection) {
return $this->connection = $connection;
}

return $this->connection;
throw new \InvalidArgumentException('You have to specify a --db-configuration file or pass a Database Connection as a dependency to the Migrations.');
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function execute(InputInterface $input, OutputInterface $output)
}
}

private function writeStatusInfosLineAligned($output, $title, $value)
private function writeStatusInfosLineAligned(OutputInterface $output, $title, $value)
{
$output->writeln(' <comment>>></comment> ' . $title . ': ' . str_repeat(' ', 50 - strlen($title)) . $value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ private function markVersions(InputInterface $input)

if ($allOption && ($rangeFromOption !== null || $rangeToOption !== null)) {
throw new \InvalidArgumentException('Options --all and --range-to/--range-from both used. You should use only one of them.');
} elseif ($rangeFromOption !== null ^ $rangeToOption !== null) {
}

if ($rangeFromOption !== null ^ $rangeToOption !== null) {
throw new \InvalidArgumentException('Options --range-to and --range-from should be used together.');
}

Expand Down Expand Up @@ -153,17 +155,17 @@ private function mark($version, $all = false)

$version = $this->configuration->getVersion($version);
if ($this->markMigrated && $this->configuration->hasVersionMigrated($version)) {
$marked = true;
if (! $all) {
throw new \InvalidArgumentException(sprintf('The version "%s" already exists in the version table.', $version));
}
$marked = true;
}

if ( ! $this->markMigrated && ! $this->configuration->hasVersionMigrated($version)) {
$marked = false;
if (! $all) {
throw new \InvalidArgumentException(sprintf('The version "%s" does not exists in the version table.', $version));
}
$marked = false;
}

if ( ! isset($marked)) {
Expand Down
9 changes: 3 additions & 6 deletions lib/Doctrine/DBAL/Migrations/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,8 @@ public function markMigrated()

private function markVersion($direction)
{
if ($direction == 'up') {
$action = 'insert';
} else {
$action = 'delete';
}
$action = $direction === 'up' ? 'insert' : 'delete';

$this->configuration->createMigrationTable();
$this->connection->$action(
$this->configuration->getMigrationsTableName(),
Expand All @@ -187,7 +184,7 @@ public function addSql($sql, array $params = [], array $types = [])
if (is_array($sql)) {
foreach ($sql as $key => $query) {
$this->sql[] = $query;
if (isset($params[$key]) && !empty($params[$key])) {
if (!empty($params[$key])) {
$queryTypes = isset($types[$key]) ? $types[$key] : [];
$this->addQueryParams($params[$key], $queryTypes);
}
Expand Down

0 comments on commit cdb33e4

Please sign in to comment.