From 9d64efcb293c519a47a99eb132ba021eda8dd98e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tihanyi=20P=C3=A9ter?= Date: Sun, 5 Jun 2016 22:49:26 +0200 Subject: [PATCH] Remove code duplicates --- src/FeatureSwitch.php | 11 ++++++++++- src/FeatureSwitchArray.php | 3 +-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/FeatureSwitch.php b/src/FeatureSwitch.php index 5e69384..199e6f5 100644 --- a/src/FeatureSwitch.php +++ b/src/FeatureSwitch.php @@ -38,7 +38,8 @@ public function addFeature(Feature\SwitchableFeatureInterface $feature) if (isset($this->features[$feature->getKey()])) { throw new \Exception(sprintf('There are already a feature with this key: %s', $feature->getKey())); } - $this->features[$feature->getKey()] = $feature; + + $this->storeFeature($feature); } /** @@ -53,4 +54,12 @@ public function isEnabled($key) } return $this->features[$key]->isEnabled(); } + + /** + * @param Feature\SwitchableFeatureInterface $feature + */ + protected function storeFeature(Feature\SwitchableFeatureInterface $feature) + { + $this->features[$feature->getKey()] = $feature; + } } \ No newline at end of file diff --git a/src/FeatureSwitchArray.php b/src/FeatureSwitchArray.php index 9f64e2a..daf950d 100644 --- a/src/FeatureSwitchArray.php +++ b/src/FeatureSwitchArray.php @@ -128,8 +128,7 @@ public function offsetSet($offset, $value) return; } - $this->features[$value->getKey()] = $value; - + $this->storeFeature($value); } /**