/** * {@inheritdoc} * * Given the following $namespaces passed in the constructor: * - Taz (lowest priority) * - Bar * - Foo (highest priority) * * Will produce the following results based on the migration's FQCN: * - (Foo\v200012, Bar\v201612) => -1 * - (Taz\v201612, Foo\v200012) => 1 * - (FooBar\v201612, Taz\v200012) => 1 * - (Taz\v201612, Taz\v201601) => delegate to fallback * - (FooBar\v201612, FooBar\v200012) => delegate to fallback * * @param DeltaInterface $version1 * @param DeltaInterface $version2 * * @return int * * @throws InvalidArgumentException */ public function compare(DeltaInterface $version1, DeltaInterface $version2) { $class1 = $version1->getMigrationClassName(); $class2 = $version2->getMigrationClassName(); if ($class1 === $class2) { // exit early in this case return 0; } $res = $this->compareNamespaces($class1, $class2); // null = could not determine order | zero = both orders are equal if (empty($res)) { // delegate sorting to the fallback comparator $res = call_user_func($this->fallbackComparator, $version1, $version2); } return $res; }
/** * @inheritdoc */ public function compare(DeltaInterface $version1, DeltaInterface $version2) { return strcmp($version1->getMigrationClassName(), $version2->getMigrationClassName()); }