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