/** * Compares two keys, and returns any errors of non matches * * @param Constraint $constraint * @param string $prefix * * @return string[] * @throws \Exception */ public function equals(Constraint $constraint, $prefix) { $prefix .= ': Constraint (' . $this->getName() . '):'; $errors = []; if ($constraint->getName() !== $this->getName()) { throw new \Exception('Comparing Incomparable Constraints'); } if ($constraint->getRemoteTable() !== $this->getRemoteTable()) { $errors[] = $prefix . 'Remote Table Does Not Match:' . "\n" . $constraint->getRemoteTable() . "\n" . $this->getRemoteTable(); } $diff = array_diff($constraint->getLocalColumns(), $this->getLocalColumns()); if (!empty($diff)) { $errors[] = $prefix . 'Extra Local Columns: ' . "\n" . implode("\n", $diff); } $diff = array_diff($this->getLocalColumns(), $constraint->getLocalColumns()); if (!empty($diff)) { $errors[] = $prefix . 'Missing Local Columns: ' . "\n" . implode("\n", $diff); } $diff = array_diff($constraint->getRemoteColumns(), $this->getRemoteColumns()); if (!empty($diff)) { $errors[] = $prefix . 'Extra Remote Columns: ' . "\n" . implode("\n", $diff); } $diff = array_diff($this->getRemoteColumns(), $constraint->getRemoteColumns()); if (!empty($diff)) { $errors[] = $prefix . 'Missing Remote Columns: ' . "\n" . implode("\n", $diff); } if ($constraint->getUpdateAction() !== $this->getUpdateAction()) { $errors[] = $prefix . 'Update Action Does Not Match:' . "\n" . $constraint->getUpdateAction() . "\n" . $this->getUpdateAction(); } if ($constraint->getDeleteAction() !== $this->getDeleteAction()) { $errors[] = $prefix . 'Delete Action Does Not Match:' . "\n" . $constraint->getDeleteAction() . "\n" . $this->getDeleteAction(); } return $errors; }