/**
  * @inheritdoc
  */
 public function doFetchAll()
 {
     $versions = new Linked();
     $classes = $this->scanner->getClasses(true);
     foreach ($classes as $class) {
         /* @var DerivedClassScanner $class */
         $className = $class->getName();
         $matches = [];
         if (preg_match($this->pattern, $className, $matches) && isset($matches[1]) && $class->isInstantiable()) {
             $migration = $this->getMigrationFactory()->create($className);
             if ($migration instanceof MigrationInterface) {
                 $id = hash('sha1', $className);
                 $version = new LinkedVersion($id, false, $migration);
                 $versions->add($version);
             }
         }
     }
     return $versions;
 }
 /**
  * Executes migrations against a collection
  *
  * @param VersionInterface $goal
  * @param OptionsInterface $options
  * @param Linked $collection
  *
  * @return Linked
  *
  * @throws InvalidArgumentException
  */
 protected function runCollection(VersionInterface $goal, OptionsInterface $options, Linked $collection)
 {
     $current = 1;
     $progress = new Progress(max($collection->count(), 1), $current);
     // dispatch COLLECTION_BEFORE
     $this->getEmitter()->dispatchCollectionBefore($goal, $options, $collection, $progress);
     $modified = new Linked();
     $comparator = $collection->getComparator();
     // IMPROVE: add tests to see if rewind is necessary
     $collection->first();
     // rewind
     foreach ($collection as $version) {
         $progress->setCurrent($current);
         $result = $this->runSingle($version, $options, $progress);
         if ($result) {
             $modified->add($version);
         }
         if ($comparator($version, $goal) >= 0) {
             break;
         }
         $current += 1;
     }
     // dispatch COLLECTION_AFTER
     $this->getEmitter()->dispatchCollectionAfter($goal, $options, $modified, $progress);
     return $modified;
 }
 /**
  * Updates versions in $available with the migration status provided by $migrated.
  *
  * @param \Baleen\Migrations\Version\VersionInterface[]|Linked $available
  * @param \Baleen\Migrations\Version\VersionInterface[]|Migrated $migrated
  *
  * @return Linked
  * @throws InvalidArgumentException
  */
 protected function prepareCollection($available, $migrated = [])
 {
     $availableCollection = new Linked($available, $this->resolver, $this->comparator);
     $migratedCollection = new Migrated($migrated, $this->resolver, $this->comparator);
     return $availableCollection->hydrate($migratedCollection)->sort();
 }
 /**
  * Fetches all versions available to all repositories in the stack and returns them as a Linked collection.
  *
  * The returned collection contains versions groups sequentially into groups that correspond to each sub-repository.
  * Each of those groups is sorted with the repository's own comparator. Therefore, its strongly recommended not to
  * sort or modify the resulting collection.
  *
  * @return Linked
  */
 public function fetchAll()
 {
     $collection = new Linked();
     foreach ($this->getRepositories() as $repo) {
         /** @var RepositoryInterface $repo */
         $versions = $repo->fetchAll();
         $collection->merge($versions);
     }
     return $collection;
 }