Chris@14: migration = $migration; Chris@14: $this->status = $status; Chris@14: array_walk($reasons, [$this, 'addReason']); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the audited migration. Chris@14: * Chris@14: * @return \Drupal\migrate\Plugin\MigrationInterface Chris@14: * The audited migration. Chris@14: */ Chris@14: public function getMigration() { Chris@14: return $this->migration; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the boolean result of the audit. Chris@14: * Chris@14: * @return bool Chris@14: * The result of the audit. TRUE if the migration passed the audit, FALSE Chris@14: * otherwise. Chris@14: */ Chris@14: public function passed() { Chris@14: return $this->status; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Adds a reason why the migration passed or failed the audit. Chris@14: * Chris@14: * @param string|object $reason Chris@14: * The reason to add. Can be a string or a string-castable object. Chris@14: * Chris@14: * @return $this Chris@14: */ Chris@14: public function addReason($reason) { Chris@14: array_push($this->reasons, (string) $reason); Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * Creates a passing audit result for a migration. Chris@14: * Chris@14: * @param \Drupal\migrate\Plugin\MigrationInterface $migration Chris@14: * The audited migration. Chris@14: * @param string[] $reasons Chris@14: * (optional) The reasons why the migration passed the audit. Chris@14: * Chris@14: * @return static Chris@14: */ Chris@14: public static function pass(MigrationInterface $migration, array $reasons = []) { Chris@14: return new static($migration, TRUE, $reasons); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Creates a failing audit result for a migration. Chris@14: * Chris@14: * @param \Drupal\migrate\Plugin\MigrationInterface $migration Chris@14: * The audited migration. Chris@14: * @param array $reasons Chris@14: * (optional) The reasons why the migration failed the audit. Chris@14: * Chris@14: * @return static Chris@14: */ Chris@14: public static function fail(MigrationInterface $migration, array $reasons = []) { Chris@14: return new static($migration, FALSE, $reasons); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Implements \Countable::count() for Twig template compatibility. Chris@14: * Chris@14: * @return int Chris@14: * Chris@14: * @see \Drupal\Component\Render\MarkupInterface Chris@14: */ Chris@14: public function count() { Chris@14: return count($this->reasons); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the reasons the migration passed or failed, as a string. Chris@14: * Chris@14: * @return string Chris@14: * Chris@14: * @see \Drupal\Component\Render\MarkupInterface Chris@14: */ Chris@14: public function __toString() { Chris@14: return implode("\n", $this->reasons); Chris@14: } Chris@14: Chris@14: /** Chris@14: * Returns the reasons the migration passed or failed, for JSON serialization. Chris@14: * Chris@14: * @return string[] Chris@14: */ Chris@14: public function jsonSerialize() { Chris@14: return $this->reasons; Chris@14: } Chris@14: Chris@14: }