Skip to content

Commit

Permalink
Trying to reduce the complexity of the execute method
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeSimonson committed Jun 20, 2015
1 parent 6f9789f commit 4361978
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/Doctrine/DBAL/Migrations/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ public function execute($direction, $dryRun = false, $timeAllQueries = false)
if (! $dryRun) {
if (!empty($this->sql)) {
foreach ($this->sql as $key => $query) {
if ($timeAllQueries !== false) {
$queryStart = microtime(true);
}
$queryStart = microtime(true);

if ( ! isset($this->params[$key])) {
$this->outputWriter->write(' <comment>-></comment> ' . $query);
Expand All @@ -278,12 +276,7 @@ public function execute($direction, $dryRun = false, $timeAllQueries = false)
$this->connection->executeQuery($query, $this->params[$key], $this->types[$key]);
}

if ($timeAllQueries !== false) {
$queryEnd = microtime(true);
$queryTime = round($queryEnd - $queryStart, 4);

$this->outputWriter->write(sprintf(" <info>%ss</info>", $queryTime));
}
$this->outputQueryTime($queryStart, $timeAllQueries);
}
} else {
$this->outputWriter->write(sprintf('<error>Migration %s was executed but did not result in any SQL statements.</error>', $this->version));
Expand Down Expand Up @@ -371,6 +364,16 @@ public function getExecutionState()
}
}

private function outputQueryTime($queryStart, $timeAllQueries = false)
{
if ($timeAllQueries !== false) {
$queryEnd = microtime(true);
$queryTime = round($queryEnd - $queryStart, 4);

$this->outputWriter->write(sprintf(" <info>%ss</info>", $queryTime));
}
}

/**
* Returns the time this migration version took to execute
*
Expand Down

0 comments on commit 4361978

Please sign in to comment.