diff options
author | Olivier Paroz <github@oparoz.com> | 2015-01-09 22:25:22 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-01-09 22:25:22 +0300 |
commit | 0e9271b1424837b8de44c47eea14867ea2dce28d (patch) | |
tree | de06a2e93f5a56be00751e3cf684251e826ab6b2 | |
parent | a8a71dbe30cc3f3a78b2bd8f4bd03af892beee12 (diff) |
Testing readability of shorter methods...
-rw-r--r-- | utility/normalizer.php | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/utility/normalizer.php b/utility/normalizer.php index 42f70b3e..09dcaace 100644 --- a/utility/normalizer.php +++ b/utility/normalizer.php @@ -85,16 +85,13 @@ class Normalizer { */ private function normalizeTraversable($data, $depth = 0) { if (is_array($data) || $data instanceof \Traversable) { - $maxArrayRecursion = 20; // + $maxArrayRecursion = 20; $normalized = array(); $count = 1; - foreach ($data as $key => $value) { if ($count++ >= $maxArrayRecursion) { - $normalized['...'] = - 'Over ' - . $maxArrayRecursion - . ' items, aborting normalization'; + $normalized['...'] = 'Over ' . $maxArrayRecursion + . ' items, aborting normalization'; break; } $normalized[$key] = $this->normalize($value, $depth); @@ -119,23 +116,18 @@ class Normalizer { if ($data instanceof \Exception) { return $this->normalizeException($data); } - // We don't need to go too deep in the recursion $maxObjectRecursion = 2; $response = $data; $arrayObject = new \ArrayObject($data); $serializedObject = $arrayObject->getArrayCopy(); - if ($depth < $maxObjectRecursion) { $depth++; $response = $this->normalize($serializedObject, $depth); } // Don't convert to json here as we would double encode - return array( - sprintf("[object] (%s)", get_class($data)), - $response - ); + return array(sprintf("[object] (%s)", get_class($data)), $response); } return null; |