From 92355708389d8e9873aeb16c167e2d154d099155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Baptiste=20Clavi=C3=A9?= Date: Sun, 27 Dec 2015 11:56:51 +0100 Subject: [PATCH] Refactor the switch in Set --- src/Set.php | 58 ++++++++++++++++++++++------------------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/src/Set.php b/src/Set.php index f18ac83..e174c9a 100644 --- a/src/Set.php +++ b/src/Set.php @@ -178,41 +178,31 @@ 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) { + return $raw['old'] !== $raw['new'] ? new Modification($raw['old'], $raw['new']) : null; + } + + if (!$new[$key] instanceof AbstractSnapshot) { + return new Modification($raw['old'], $raw['new']); + } + + if (!$new[$key]->isComparable($old[$key])) { + return new Modification($raw['old'], $raw['new']); } - // @codeCoverageIgnoreEnd - // PHPUnit coverage wtf end + + $set = new static; + $set->compute($old[$key], $new[$key]); + + if (0 < count($set)) { + return $set; + } + + return null; } /**