Skip to content

Commit

Permalink
Refactor the switch in Set
Browse files Browse the repository at this point in the history
  • Loading branch information
Taluu committed Dec 27, 2015
1 parent a2afd1d commit 0f3ad9a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 36 deletions.
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@
},

"require": {
"php": "^5.4|^7.0",
"symfony/property-access": "^2.5|^3.0"
"php": ">=7.0",
"symfony/property-access": "^3.0"
},

"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
}
}
}
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 0f3ad9a

Please sign in to comment.