Skip to content

Commit

Permalink
Merge pull request #354 from GuySartorelli/patch-1
Browse files Browse the repository at this point in the history
FIX Return correct changed fields when fromRecord is null
  • Loading branch information
michalkleiner authored Mar 16, 2022
2 parents 7cedcf6 + 28e4080 commit 3796337
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/DataDifferencer.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,11 @@ public function ChangedFields()
*/
public function changedFieldNames()
{
$diffed = clone $this->fromRecord;
if ($this->fromRecord) {
$diffed = clone $this->fromRecord;
} else {
$diffed = clone $this->toRecord;
}
$fields = array_keys($diffed->toMap());

$changedFields = [];
Expand All @@ -267,7 +271,7 @@ public function changedFieldNames()
if (in_array($field, $this->ignoredFields)) {
continue;
}
if ($this->fromRecord->$field != $this->toRecord->$field) {
if (!$this->fromRecord || $this->fromRecord->$field != $this->toRecord->$field) {
$changedFields[] = $field;
}
}
Expand Down

0 comments on commit 3796337

Please sign in to comment.