Skip to content

Commit

Permalink
Remove unnecessary conditions in set and reset methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Sieg committed May 19, 2017
1 parent 6121f4c commit 0ffb7b4
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions Source/DataContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,13 @@ public function get($key)
$data = $this->getData();
$result = null;

if (strpos($key, $this->getSeparator())) {
$path = $this->getPath($key);
if ($lastLevelData = $this->getDeepLevelLink($data, $path) and is_array($lastLevelData)) {
$mainKey = end($path);
if (array_key_exists($mainKey, $lastLevelData)) {
$result = $lastLevelData[$mainKey];
}
};
} elseif (isset($data[$key])) {
$result = $data[$key];
}
$path = $this->getPath($key);
if ($lastLevelData = $this->getDeepLevelLink($data, $path) and is_array($lastLevelData)) {
$mainKey = end($path);
if (array_key_exists($mainKey, $lastLevelData)) {
$result = $lastLevelData[$mainKey];
}
};

return $result;
}
Expand All @@ -93,14 +89,10 @@ public function set($key, $value)
{
$data = &$this->data;

if (strpos($key, $this->getSeparator())) {
$path = $this->getPath($key);
$lastLevelData = &$this->ensureStructure($data, $path);
$mainKey = end($path);
$lastLevelData[$mainKey] = $value;
} else {
$data[$key] = $value;
}
$path = $this->getPath($key);
$lastLevelData = &$this->ensureStructure($data, $path);
$mainKey = end($path);
$lastLevelData[$mainKey] = $value;
}

/**
Expand Down

0 comments on commit 0ffb7b4

Please sign in to comment.