Skip to content
Permalink
Browse files

Port fix for #6224 to master.

Fix issues with maxDimensions() to 3.0 as well.
  • Loading branch information...
markstory committed Apr 1, 2015
1 parent 4604761 commit 4c29d7de06850a712f12c63fc48ae57684cd7d8f
Showing with 14 additions and 2 deletions.
  1. +6 −2 src/Utility/Hash.php
  2. +8 −0 tests/TestCase/Utility/HashTest.php
@@ -798,10 +798,14 @@ public static function maxDimensions(array $data)
$depth = [];
if (is_array($data) && reset($data) !== false) {
foreach ($data as $value) {
$depth[] = static::dimensions((array)$value) + 1;
if (is_array($value)) {
$depth[] = static::dimensions($value) + 1;
} else {
$depth[] = 1;
}
}
}
return max($depth);
return empty($depth) ? 0 : max($depth);
}
/**
@@ -282,6 +282,14 @@ public function testDimensions()
*/
public function testMaxDimensions()
{
$data = [];
$result = Hash::maxDimensions($data);
$this->assertEquals(0, $result);
$data = ['a', 'b'];
$result = Hash::maxDimensions($data);
$this->assertEquals(1, $result);
$data = ['1' => '1.1', '2', '3' => ['3.1' => '3.1.1']];
$result = Hash::maxDimensions($data);
$this->assertEquals($result, 2);

0 comments on commit 4c29d7d

Please sign in to comment.
You can’t perform that action at this time.