Skip to content

Commit

Permalink
Merge pull request #36 from Taluu/refactor-set
Browse files Browse the repository at this point in the history
Refactor things
  • Loading branch information
Taluu committed Jan 8, 2016
2 parents 196992e + 0ad3481 commit e6b43cd
Showing 1 changed file with 18 additions and 34 deletions.
52 changes: 18 additions & 34 deletions src/Set.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,41 +178,25 @@ private function computeEntry(AbstractSnapshot $old, AbstractSnapshot $new, $key
return new Removal($this->getRawData($old[$key]));
}

$values = ['old' => $this->getRawData($old[$key]),
'new' => $this->getRawData($new[$key])];

switch (true) {
// type verification
case gettype($old[$key]) !== gettype($new[$key]):
return new Modification($values['old'], $values['new']);

// could we compare two snapshots ?
case $old[$key] instanceof AbstractSnapshot:
if (!$new[$key] instanceof AbstractSnapshot) {
return new Modification($values['old'], $values['new']);
}

if (!$old[$key]->isComparable($new[$key])) {
return new Modification($values['old'], $values['new']);
}

$set = new static;
$set->compute($old[$key], $new[$key]);

if (0 < count($set)) {
return $set;
}

return null;

// unknown type : compare raw data
case $values['old'] !== $values['new']:
return new Modification($values['old'], $values['new']);
// PHPUnit coverage wtf start
// @codeCoverageIgnoreStart
$raw = [
'old' => $this->getRawData($old[$key]),
'new' => $this->getRawData($new[$key])
];

if ($old[$key] instanceof AbstractSnapshot && $new[$key] instanceof AbstractSnapshot && $new[$key]->isComparable($old[$key])) {
$set = new static;
$set->compute($old[$key], $new[$key]);

if (0 < count($set)) {
return $set;
}
}
// @codeCoverageIgnoreEnd
// PHPUnit coverage wtf end

if ($raw['old'] !== $raw['new']) {
return new Modification($raw['old'], $raw['new']);
}

return null;
}

/**
Expand Down

0 comments on commit e6b43cd

Please sign in to comment.