/**
  * @param  int                                  $offset
  * @param  int                                  $totalCount
  * @return ErrorResult|FinishResult|ValidResult
  */
 public function run($offset, $totalCount = null)
 {
     if ($offset == 0) {
         $this->migrationManager->createSchemaTable();
     }
     $currentVersion = $this->migrationManager->getCurrentVersion();
     if (!$totalCount) {
         $totalCount = count($this->migrationManager->getMigrationsForVersion($currentVersion));
     }
     $migration = $this->migrationManager->getNextMigrationForVersion($currentVersion);
     if (null === $migration) {
         return new FinishResult($offset, $totalCount);
     }
     try {
         $this->migrationManager->apply($migration);
     } catch (\Exception $e) {
         $reflection = new \ReflectionClass(get_class($migration));
         $classFile = $reflection->getFileName();
         return new ErrorResult($e->getMessage(), $e, array('deltaFile' => $classFile, 'deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
     }
     return new ValidResult($offset + 1, $totalCount, array('deltaVersion' => $migration->getVersion(), 'deltaLabel' => $migration->getLabel()));
 }