Skip to content

Commit

Permalink
Who's afraid of multiple return points?
Browse files Browse the repository at this point in the history
  • Loading branch information
carlwiedemann committed Jun 2, 2014
1 parent 142c3bf commit 84b95d3
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions core/lib/RenderAPI/Accessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,21 @@ public static function create($value, $themed = FALSE) {
* @return mixed
*/
public function get($key) {

if ($this->value instanceOf AbstractWeightedCollection) {
// If this is a component of an array, recurse.
$return = Accessor::create($this->value->get($key), $this->themed);
}
elseif (is_object($this->value) && isset($this->value->$key)) {
// If this is a struct, treat as much.
$return = Accessor::create($this->value->$key, $this->themed);
return Accessor::create($this->value->get($key), $this->themed);
}
elseif (is_array($this->value) && isset($this->value[$key])) {
$return = Accessor::create($this->value[$key], $this->themed);
return Accessor::create($this->value[$key], $this->themed);
}
elseif ($this->value instanceOf stdClass && isset($this->value->$key)) {
// If this is a struct, treat as much.
return Accessor::create($this->value->$key, $this->themed);
}
else {
// This didn't find anything, so it must be invalid key.
$return = Accessor::create(NULL);
return Accessor::create(NULL);
}

return $return;
}

/**
Expand All @@ -94,19 +91,28 @@ public static function convert($variable, $themed) {
foreach ($variable->getAll() as $key => $value) {
$return[$key] = Accessor::convert($value, $themed);
}
return $return;
}
elseif (is_array($variable)) {
// An array of potential values.
$return = array();
foreach ($variable as $key => $value) {
$return[$key] = Accessor::convert($value, $themed);
}
return $return;
}
elseif ($variable instanceOf stdClass) {
// Iterate through stdClass parameters.
$return = array();
foreach ((array) $variable as $key => $value) {
$return[$key] = Accessor::convert($value, $themed);
}
return (object) $return;
}
else {
// This is likely a scalar or stdClass.
$return = $variable;
return $variable;
}
return $return;
}

/**
Expand Down

0 comments on commit 84b95d3

Please sign in to comment.